TechoSagar: Automorphic Number

Automorphic Number

Write a program to check whether a given number is Automorphic number or not.
A number is called Automorphic number if and only if its square ends in the same digits as the number itself.
For example, 762 = 5776 which ends with 76 therefore it is a automorphic number.

Input:
The first line of the input contains T denoting the total number of testcases. Each of the next T lines contains a positive integer N denoting the value of a number.

Output:
Output "Automorphic" if given number is Automorphic else "Not Automorphic" .

Constraints:
1<=T<=100
1<=N<=1000

Example:
Input:
2
1
16
Output:
Automorphic
Not Automorphic

Your Code
#include<iostream>

using namespace std;
#include<math.h>
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int x=n;
long int s;
s=n*n;
int  num=0;
while(n!=0)
{
n=n/10;
num++;
}
int i,number=0;
for(i=0; i<num; i++)
{
int k;
k=s%10;
number=number+k*pow(10,i);
s=s/10;
}
//cout<<number<<" "<<n<<endl;
if(number==x)
cout<<"Automorphic"<<endl;
else
cout<<"Not Automorphic"<<endl;
}
return 0;

}

Follow us

Follow Bijendra Kumar on Facebook