C program to print first 8 automorphic numbers

Print first 8 automorphic number in c programming.
For example:
First 8 automorphic numbers are:
1
5
6
25
76
376
625
9376


#include<stdio.h>

void main()
{

int i,count=0;
long int n,no=0,s,rem=0,ans=0,temp;

clrscr();

printf("First 8 automorphic no.:\n");

for(i=1;count<8;i++)
{
n=i;

s=n*n;
temp=10;

while(n>0)
{
rem=s%temp;

if(i==rem)
{
ans=1;
break;
}
n=n/10;
temp=temp*10;
}


if(ans==1)
{
printf("\n%d ",i);
count++;
}
ans=0;

}
getch();


}

c program to print first 8 automorphic numbers


1 comments: