ADAM NUMBER OR NOT

Consider the following I/O samples.




SAMPLE INPUT: 221

SAMPLE OUTPUT:  ADAM NUMBER

An Adam number is the square of the given number is equal to the reverse of square of reverse of the given number.

12
Square(12) = 144
Reverse(Square(Reverse(12)))= 144





C PROGRAM:

#include <stdio.h>

int main()

{

    int r,p,m,n,rev,a,c,z;

    r=0;

    rev=0;

    scanf("%d",&z);

    n=z;

    c=n*n;

    while(n)

    {

        m=n%10;

        r=r*10+m;

        n=n/10;

    }

    p=r*r;

    while(c)

    {

        a=c%10;

        rev=rev*10+a;

        c=c/10;

    }

    if(rev == p)

        printf("ADAM NUMBER");

    else

        printf("NOT A ADAM NUMBER");

    return 0;

}




OUTPUT:

              




The given source code in C program "FOR ADAM NUMBER OR NOT" is short and simple to understand. The source code is well tested in DEV-C++ and is completely error free. 
If you have any feedback about this article and want to improve this, please comment in the comment section.

Comments

Popular posts from this blog

C PROGRAM FOR Mth LARGEST AND Mth SMALLEST ELEMENT IN AN ARRAY

C PROGRAM TO CHECK BALANCED PARENTHESIS - ( { [

TRIANGULAR NUMBER OR NOT