Automorphic Number.

Program to check whether a given number is Automorphic number or not.


A number is said to an automorphic number if its "square" ends with the same digits as the number itself.
for example, 5, 6, 76, 376 etc are automorphic number as its square are 25, 36, 5776, 141376 and 5, 6, 76, 376 are present as the last digits.







SOURCE CODE


import java.io.*;
public class Automorphic
{
    public static void main(String args[])throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.print("Enter a number    :");
        int a=Integer.parseInt(br.readLine());
        int sq=a*a;
        int rem,n=a,j=1;
        while(n>0)
        {
            rem=n%10;
            n=n/10;
            j*=10;
        }
        if(sq%j==a)
        System.out.println("Yes, it is an Automorphic No.");
        else
        System.out.println("No, it is not an Automorphic No.");
    }
}


OUTPUT






Click Here to download program.

If you have any question then leave a comment below I will do my best to answer that question.



Comments

Popular posts from this blog

Pattern of your own name.

A Very Big Sum - Hacker Rank

[Question 4] ICSE 2014 Computer Application Solved - movieMagic.