Thursday 19 June 2014

C++ program to print Adam numbers from 1 to n



Here is a C++ program to print Adam numbers from 1 to n


 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;
    for(int i=0;i<=n;i++)
    {
       sqr1=i*i;
       revers1=revers(i);
       revers2=revers1*revers1;
       if(revers(revers2)==sqr1)
           cout<<i<<" ";
    }
    return 0;
}

Any questions regarding to program please write in comments.

No comments:

Post a Comment