Automorphic Number

 



//Entered number is automorphic number or not?

#include<iostream>

#include<math.h>

using namespace std;


int automorphic(int n)

{

int sq, t, x, len=0,s=0;

// cout<<"Enter any number: ";

// cin>>n;

sq=n*n;

// cout<<"Square of "<<n<<" is "<<sq<<endl;

x=n;

//Find the length of the entered number

while(n!=0)

{

len++;

n=n/10;

}

n=x;

for(int i=0;i<len;i++)

{

t=sq%10;

s=s+pow(10,i)*t;

sq=sq/10;

}

return s;

}


int main()

{

int i, n, ans;

cout<<"Enter N: ";

cin>>n;

cout<<"Automorphic Numbers from 1 to "<<n<<" are:\n";

for(i=1;i<=n;i++)

{

ans=automorphic(i);

if(ans==i)

cout<<i<<"\t";

}

return 0;

}


Watch Video for the above program explanation




No comments

Post your comments

Powered by Blogger.