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

How can I run a C++ program directly from Windows?

How-can-I-run-a-C-program-directly-from-Windows