# Find out all Armstrong numbers present within a given range

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

Program in C

Code:

#include <stdio.h>
#include<math.h>
int main()
{
int i, firstnum, endnumber;
printf ("Enter the first number:");
scanf ("%d", &firstnum);
printf ("Enter the second number:");
scanf ("%d", &endnumber);

printf ("Armstrong Numbers between %d and %d: \n", firstnum, endnumber);
for(i=firstnum;i<=endnumber;i++)
{
int num2=i;
int num1=i;
int sum=0;
while(num1!=0)
{
int rem=num1%10;
num1=num1/10;
sum=sum+rem*rem*rem;
}
if(sum==num2)
printf("%d ",i);

}
return 0;
}

Input/Output:
Enter the first number:10
Enter the second number:370
Armstrong Numbers between 10 and 370:
153 370

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

Program in C++

Code:

#include<iostream>
using namespace std;
int main()
{
int range1,range2;
cout<<"Enter a range:";
cin>>range1>>range2;
cout<<"Armstrong numbers between "<<range1<<" and "<<range2<<" are: ";
for(int i=range1;i<=range2;i++)
{
int num2=i;
int num1=i;
int sum=0;
while(num1!=0)
{
int rem=num1%10;
num1=num1/10;
sum=sum+rem*rem*rem;
}
if(sum==num2)
cout<<i<<" ";
}
}

Input/Output:
Enter a range:
370
500
Armstrong numbers between 370 and 500 are: 370 371 407

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

Program in Java

Code:

import java.util.Scanner;
public class ArmstrongNumberInRange {

public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
int firstnumber, endnumber, i;
System.out.println("Enter the First number:");
firstnumber=cs.nextInt();
System.out.println("Enter the Last number:");
endnumber=cs.nextInt();
System.out.println("Armstrong numbers between "+firstnumber+" and "+endnumber+" are:");
for(i=firstnumber;i<=endnumber;i++)
{
int num2=i;
int num1=i;
int sum=0;
while(num1!=0)
{
int rem=num1%10;
num1=num1/10;
sum=sum+rem*rem*rem;
}
if(sum==num2)
System.out.print(i+" ");

}
cs.close();
}
}

Input/Output:
Enter the First number:
20
Enter the Last number:
500
Armstrong numbers between 20 and 500 are:
153 370 371 407

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

Program in Python
Write a program to find out all Armstrong number in python
Code:

print("Enter a range:")
range1=int(input())
range2=int(input())
print("Armstrong numbers between ",range1," and ",range2," are: ")
for i in range(range1,range2+1):
num2=i
num1=i
sum=0
while(num1!=0):
rem=num1%10
num1=int(num1/10)
sum=sum+rem*rem*rem
if sum==num2:
print(i,end=" ")

Input/Output:
Enter a range:
100
1000
Armstrong numbers between  100  and  1000  are:
153 370 371 407