C program to check the given number is Adam’s number: Adam number is a number when reversed, the square of the number and the square of the reversed number should be numbers which are reverse of each other.
Input : 12
Explanation: Square of 12 = 144
Reverse of 12 = 21
Square of 21 = 441
Now Square of 12 and square of reverse of 12 are reverse of each other. Therefore 12 is Adam number.
Code for C program to check the given number is Adam’s number
#include<stdio.h>
#include<conio.h>
void main()
{
int reverse(int);
int square(int);
int n,n1,n2,sn,sn1,rsn1;
scanf("%d",&n);
n1=reverse(n);
n2=reverse(n1);
sn=square(n2);
sn1=square(n1);
rsn1=reverse(sn1);
if(n2==n && sn==rsn1)
printf("It is an Adam’s number");
else
printf("It is not an Adam’s number");
}
int reverse(int n)
{
int rev=0,a;
while(n>0)
{
a=n%10;
rev=rev*10+a;
n=n/10;
}
return rev;
}
int square(int sn)
{
int s=sn*sn;
return s;
}
Output
12
It is an Adam’s number
Read: C program to check whether the given number is an Armstrong number