+ 1
How to print automorphic number between 1 to 1000.....plz make this in simple way
Automorphic number is a number whose ends in the same digits as the number itself.... for e.g. 25,625 Arun Tomar Helga Hans Larry HAWKEYE Sreejith Veerendra Kushwaha Fata1 Err0r Purab Gupta [A^dr3w] Dev
6 odpowiedzi
+ 3
import java.util.Scanner;
public class main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("Type a number between 1 to 1000 :");
int number = sc.nextInt();
int length = Integer.toString(number).length();
int comparing = (int)Math.pow(number, 2);
comparing = comparing % (int)Math.pow(10, length);
if( number == comparing){
System.out.println(number + " is Automorphic number");
}
else{
System.out.println(number + " is not an Autoporphic number");
}
}
}
//sigh... one in here looks better than my code ( https://www.geeksforgeeks.org/automorphic-number/ )
+ 5
Harsh Agrawal to print all automorphic numbers between 1 to 100, put Jang Jaeung's code in a for loop and remove scanner
....
....
for (int number=1; number<=100; number++)
{
int length = Integer.toString(number).length();
...
...
if(number == comparing){
System.out.print(number)
}
...
...
+ 1
Share your ideas, show us your attempts, we will help you.
I would use "for loop" for this purpose and remainder operator (%).
+ 1
Hi
public class Automorphic
{
public static void main(String[] args) {
System.out.println("All Automorphic Numbers between 1 and 1000.\n===========================================");
int div = 10;
for(int num = 1; num <= 1000; num++)
{
if (div >= num)
{
if((num * num) % div == num)
System.out.println( num );
}
else if (div <= num)
{
div * = 10;
if((num * num) % div == num)
System.out.println( num );
}
}
}
}
https://code.sololearn.com/cMWOeOYm0mln/?ref=app
hope this helps
0
Can someone code in python plzz
0
https://code.sololearn.com/cYS2O4BQRm2e/?ref=app
print("All Automorphic Numbers between 1 and 1000.\n===========================================")
div = 10
for num in range(1,1000):
if (div >= num):
if((num * num) % div == num):
print( num )
elif (div <= num):
div *= 10
if((num * num) % div == num):
print( num )