C program to check number is Automorphic or not


                                                  First we need to understand What is Automophic numbers? A number whose square's last degit(s) are equal to that number. Some example of automorphic number is 1, 5, 6, 25, 76

For example
                                          5 ^2  =  25
                                                   So here square of 5 is 25 and last digit of 25 is 5. And its equal to 5.

Source Code to check Automorphic number

#include<stdio.h>

void main()
{
    long int n,no=0,s,rem=0,ans=0,temp;

    clrscr();

    printf("Enter a number: ");
    scanf("%ld",&n);

    no=n;
    s=n*n;
    temp=10;

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

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

    }

    if(ans==1)
    {
         printf("no is automorphic");
    }
    else
    {
         printf("no is not automorphic");
    }
    getch();

}


c program for Automorphic number

4 comments:

  1. how about a program that prints out the first eight (8) automorphic numbers???

    Desired Output:

    The first nine automorphic numbers are:
    1
    5
    6
    25
    76
    376
    625
    9376

    ReplyDelete
    Replies
    1. Source code to print first 8 automorphic number in c are as below. just click on link. And if you have any further query please share with us.
      C program to print first 8 automophic numbers.

      Delete
  2. WHAT IF A RANGE IS GIVEN BY USER?
    AND THEN WE HAVE TO FIND AUTOMORPHIC NO WITHIN THAT RANGE?

    ReplyDelete
    Replies
    1. @Yamshi For you question check this program i think its helpful for you.
      http://www.programmingcampus.com/2013/09/c-program-to-print-first-8-automorphic-numbers.html

      Delete