# Find out all Automorphic numbers present within a given range

Write a C program to find out all Automorphic numbers present within a given range.
or Write a program to find out all Automorphic numbers present within a given range in C.

Program in C

Code:

/*Write a C program to find out all Automorphic numbers present within a given range. or Write a program to find out all Automorphic numbers present within a given range Using C*/

#include<stdio.h>
int main()
{
int range1,range2,j,i;
printf("Enter a range:");
scanf("%d %d",&range1,&range2);
printf("Automorphic numbers between %d and %d are: ",range1,range2);
for( i=range1;i<=range2;i++)
{   int num=i;
int sqr=num*num;
int flag=0;
while(num>0)
{
if(num%10 != sqr%10)
{flag=-1;
break;
}
num=num/10;
sqr=sqr/10;
}
if(flag==0)
printf("%d ",i);
}
}

Input/Output:
Enter a range:
20
100
Automorphic numbers between 20 and 100 are: 25 76

Write a C++ program to find out all Automorphic numbers present within a given range. or Write a program to find out all Automorphic numbers present within a given range in C++.

Program in C++

Code:

/*Write a C++ program to find out all Automorphic numbers present within a given range. or Write a program to find out all Automorphic numbers present within a given range using C++*/

#include<iostream>
using namespace std;
int main()
{
int range1,range2;
cout<<"Enter a range:";
cin>>range1>>range2;
cout<<"Abundant numbers between "<<range1<<" and "<<range2<<" are: ";
for(int i=range1;i<=range2;i++)
{   int num=i;
int sqr=num*num;
int flag=0;
while(num>0)
{
if(num%10 != sqr%10)
{flag=-1;
break;
}
num=num/10;
sqr=sqr/10;
}
if(flag==0)
cout<<i<<"\n";
}
}

Input/Output:
Enter a range:
101
1000
Abundant numbers between 101 and 1000 are: 376
625

Write a JAVA program to find out all Automorphic numbers present within a given range. or Write a program to find out all Automorphic numbers present within a given range in Java.

Program in Java

Code:

/*Write a JAVA program to find out all Automorphic numbers present within a given range. or Write a program to find out all Automorphic numbers present within a given range using Java*/

import java.util.Scanner;
public class FindAutomorphicNumbersInRange {

public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
int range1,range2;
System.out.println("Enter a range:");
range1=cs.nextInt();
range2=cs.nextInt();
System.out.println("Automorphic numbers between "+range1+" and "+range2+" are: ");
for(int i=range1;i<=range2;i++)
{   int num=i;
int sqr=num*num;
int flag=0;
while(num>0)
{
if(num%10 != sqr%10)
{
flag=-1;
break;
}
num=num/10;
sqr=sqr/10;
}
if(flag==0)
System.out.print(i+" ");
}
cs.close();
}
}

Input/Output:
Enter a range:
1000
10000
Automorphic numbers between 1000 and 10000 are:
9376

Write a PYTHON to find out all Automorphic numbers present within a given range. or Write a program to find out all Automorphic numbers present within a given range in Python.

Program in Python

Code:

'''Write a Python program to find out all Automorphic numbers present within a given range. or Write a program to find out all Automorphic numbers present within a given range using Python '''

print("Enter a range:")
range1=int(input())
range2=int(input())
print("Perfect numbers between ",range1," and ",range2," are: ")
for i in range(range1,range2+1):
num=i
sqr=num*num
flag=0
while num!=0:
if(num%10 != sqr%10):
flag=-1
break
num=int(num/10)
sqr=int(sqr/10)
if(flag==0):
print(i,end=" ")

Input/Output:
Enter a range:
10
10000000
Perfect numbers between  10  and  10000000  are:
25 76 376 625 9376 90625 109376 890625 2890625 7109376