Like us on google+

Saturday, 9 November 2013

Widgets

C PROGRAM TO CHECK WHETHER THE ENTERED NUMBER IS AUTOMORPHIC OR NOT.

An automorphic number is a number whose square contains the same number as last digits or digit.
Example :, 52 = 25,62 = 36, 762= 5776, and 8906252 = 793212890625

Program:

1:  #include<stdio.h>  
2:  int main()  
3:  {  
4:    long int n,num,sqr,rem=0;  
5:    int temp,ans;  
6:    printf("Enter a number: ");  
7:    scanf("%ld",&n);  
8:    num=n;  
9:    sqr=n*n;  
10:    temp=10;  
11:    printf("square of %ld is %ld ",n,sqr);  
12:    while(n>0)  
13:    {  
14:       rem=sqr%temp;  
15:       if(num==rem)  
16:       {  
17:           ans=1;  
18:           break;  
19:       }  
20:       n=n/10;  
21:       temp=temp*10;  
22:    }  
23:    if(ans==1)  
24:    {  
25:       printf("\n %d is automorphic",num);  
26:    }  
27:    else  
28:    {  
29:       printf("\n %d is not automorphic",num);  
30:    }  
31:   return 0;  
32:  } 
Sample output:
Enter a number:76
square of 76 is 5776
76 is automorphic

SHARE THIS POST   

  • Facebook
  • Twitter
  • Myspace
  • Google Buzz
  • Reddit
  • Stumnleupon
  • Delicious
  • Digg
  • Technorati
About us:
Hi guys Sandesh and Rajesh here ... studing engineering in PESIT started this blog as a google contest and also we love blogging ...Hope u like it ...Encourage us by liking us on g+... Any queries dont hesitate to ask Read More →

1 comments: