"The best way to cheer yourself up is to try to cheer somebody else up." Mark Twain
Showing posts with label Automorphic No.. Show all posts
Showing posts with label Automorphic No.. Show all posts

Tuesday, February 2, 2010

WAP in C++ to check whether the inputed integer is automorphic or not


In Mathematics an automorphic number (sometimes referred to as a circular number) is a number whose square ends in the same digits as number itself.
For example, 52 = 25, 762 = 5776



#include<iostream.h>
#include<conio.h>
void main()
{
int n, d;
long sq;
cout << "\n Enter a Number :";
cin >> n ;
sq =(long) n * n ;
int  y, r;
long x = sq;
y = n;
while(y!=0)
{
r= y%10;
d = (int) (x%10);
x = x/10;
y = y/10;
if(r ! =  d)
cout << " \ n NOT an Automorphic Number.";
getch();
exit(1);
}
cout << " \ n an Automorphic Number.";getch();


}
C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off.
Now Playing: Ballade Pour Adeline

About Me

My photo
I m an IT lecturer of a college. I love social-work. I want to do something beneficial for society before dying , that can promote our society, to some extent.