Wednesday, 18 June 2014

C++ program to check whether a given number is Adam number or not



Here is a C++ program to check whether a given number is Adam number or not


 SOURCE CODE OUTPUT
#include<iostream>
#include<math.h>
using namespace std;
int revers(int num)
{
    int rev = 0, mod;
        while (num > 0) {
                mod = num % 10;
                rev = (rev * 10) + mod;
                num = num / 10;
        }
        return rev;
}
int main()
{
    long double fact=1,y,sqr1,revers2,revers1;
    int n;
    cout<<"Enter the value of n ";
    cin>>n;
    sqr1=n*n;
    revers1=revers(n);
    revers2=revers1*revers1;
    if(revers(revers2)==sqr1)
           cout<<n<<" is Adam number ";
    else
        cout<<n<<" is not Adam number ";
    return 0;
}

Any questions regarding to program please write in comments.

No comments:

Post a Comment