C Program to check whether the number is an Automorphic Number or Not

Write a program to check whether the number is an Automorphic number or not.

Note: A number is called an Automorphic number if and only if its square ends in the same digits as the number itself.

Example: (76)^2 = 5776 , (5)^2 = 25

Input Format
The input contains a single integer N.

Output Format
Print the output as AUTOMORPHIC or NOT AUTOMORPHIC

Constraint
1<=N<=10^8

Sample Input 1

76

Sample Output 1

AUTOMORPHIC 76 76

Code:

#include<stdio.h>
int main(){
	long int n,a,b,c;
 	scanf("%ld",&n);
    int temp=n;

    b=temp*temp;
    
    if (n<10){
    
    a=n%10;
    c=b%10;

     if(a==c) printf("AUTOMORPHIC %ld %ld",a,c);
     else printf("NOT AUTOMORPHIC %ld %ld",a,c);
    }
    
    
    else if(n<100){
    
    a=n%100;
    c=b%100;

     if(a==c) printf("AUTOMORPHIC %ld %ld",a,c);
     else printf("NOT AUTOMORPHIC %ld %ld",a,c);
    }
    
    else if(n<1000){
           
    a=n%1000;
    c=b%1000;

     if(a==c) printf("AUTOMORPHIC %ld %ld",a,c);
     else printf("NOT AUTOMORPHIC %ld %ld",a,c);

    }
    else if(n<10000){
           
    a=n%10000;
    c=b%10000;

     if(a==c) printf("AUTOMORPHIC %ld %ld",a,c);
     else printf("NOT AUTOMORPHIC %ld %ld",a,c);

    }

    
}
Code language: C/AL (cal)

Leave a Comment