Computer Science, asked by rudrakshadutta75, 5 months ago

Write a program in java to display all the Automorphic Numbers from 1 to 2000. (Example: 6, 25) [Since 6 2 = 36 and in 36 last digit = 6; similarly, 25 2 = 625 and in 625 last two digits = 25] [Hint: In the square form of the number if the last part is equal to the original number then the number is termed as Automorphic Number.]

Answers

Answered by BrainlyProgrammer
6

\huge\star\underbrace{\mathtt\orange{⫷❥QuEsTiOn⫸}}\star

  • To print Automorphix no. between 1 to 2000

________________

\huge\star\underbrace{\mathtt\red{⫷❥ᴀ᭄} \mathtt\green{n~ }\mathtt\blue{ §} \mathtt\purple{₩}\mathtt\orange{Σ} \mathtt\pink{R⫸}}\star

import java. util. *;

class auto

{

public static void main (String ar[])

{

int I;

for (I=1;I<=2000;I++)

{

int k=I, c=0;

int k2=(int) k*k;

while(k! =0)

{

c++;

k/=10;

}

if (k2%(Math.pow(10, c) ==I)

System. out. println ("Automorphic no. "+I ) ;

}

}

}

Answered by anindyaadhikari13
3

Question:-

➡ Write a program in Java to display all the Automorphic Numbers from 1 to 2000.

Program:-

class Automorphic

{

static boolean isAutomorphic(int n)

{

int c=0, a=n, b=a*a;

while(a!=0)

{

c++;

a/=10;

}

return (n%(int)Math.pow(10,c)==b);

}

public static void main(String s[])

{

System.out.println("Automorphic Numbers from 1 to 2000 are..");

for(int i=1;i<=2000;i++)

{

if(isAutomorphic(i))

System.out.print(i+" ");

}

}// main()

}// class.

Similar questions