Automorphic number


/* Write a program to check whether an entered number is an automorphic number or not.
 * A number is said to be an automorphic number if it is present in the last digits of its square
 */
import java.io.*;
class automorphic
{
public static void main()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int m,b,p;
double r=0;
System.out.println("Enter a number");
int n=Integer.parseInt(br.readLine());
m=n;
p=m*m;
int c=0;
do
{
c++;
m=m/10;
}while(m!=0);
int q= p%(int)Math.pow(10,c);

if(n==q)
System.out.println(n+" is an Automorphic number");
else
System.out.println(n+" is not an Automorphic number");
}}

Comments

  1. i dont get why you have done c++ or taken c

    ReplyDelete
  2. 'c' is to count the frequency of digits in the entered number

    ReplyDelete
  3. awesome but could you explain what is being done in q= p%(int)Math.pow(10,c);

    ReplyDelete
    Replies
    1. public class Automorphic
      {
      public static void main(int num)
      {
      int a,b;
      a=num;
      b=a*a;
      int c=0;
      do
      {
      c++;
      a=a/10;
      }
      while(a!=0);
      int x=b%(int)Math.pow(10,c);
      if(num==x)
      System.out.println(num +" is an Automorphic number");
      else
      System.out.println(num +" is not an Automorphic number");
      }
      }

      if num=5
      b=25
      a=a/10 \\ a= 2
      x= 25%10
      x=5
      got it!!!!!!!!!!!!

      Delete
    2. No a/10 is 0 but c++ = 1

      Delete
    3. This comment has been removed by the author.

      Delete
  4. it worked! but plz explain q= p%(int)Math.pow(10,c);
    thanks.

    ReplyDelete
    Replies
    1. public class Automorphic
      {
      public static void main(int num)
      {
      int a,b;
      a=num;
      b=a*a;
      int c=0;
      do
      {
      c++;
      a=a/10;
      }
      while(a!=0);
      int x=b%(int)Math.pow(10,c);
      if(num==x)
      System.out.println(num +" is an Automorphic number");
      else
      System.out.println(num +" is not an Automorphic number");
      }
      }

      if num=5
      b=25
      a=a/10 \\ a= 2
      x= 25%10
      x=5
      got it

      Delete
  5. Thora simple Mai prog batana Bhai

    ReplyDelete

Post a Comment

Popular posts from this blog

Bubble sort

Prime number