Monday, July 2, 2018

C program to check if number is Automorphic

#include<stdio.h>
  int main()
  {
    long int n,num,sqr,rem=0;
    int temp,ans;
    printf("Enter a number: ");
    scanf("%ld",&n);
    num=n;
    sqr=n*n;
    temp=10;
    printf("square of %ld is %ld ",n,sqr);
    while(n>0)
    {
       rem=sqr%temp;   //gives units place digit of square of given number
       if(num==rem)
       {
           ans=1;
           break;
      }
      n=n/10;
       temp=temp*10;
    }
    if(ans==1)
    {
       printf("\n %d is automorphic",num);
    }
    else
    {
       printf("\n %d is not automorphic",num);
    }
   return 0;
 }

No comments:

Post a Comment

Sacred Thought

5 May 2024 Hari Om Verse 50-51, chapter two:  In this chapter two Shree krishna explains a simple way of living. Free from desires and void ...