# Print Strong numbers in a given range(1 to n)

### Example:-

145, 40585........

#### Sample Input/Output:-

Sample Input First: 10 200                    Sample Output First: 145

Sample Input Second: 50 500000         Sample Output Second145 40585

#### Data requirement:-

Input Data:- range1, range2

Output Data:-i

Additional Data:-num1, num2, j, fact, sum

Program in C

Here is the source code of the C Program to Find out all Strong numbers present within a given range.

Code:

#include<stdio.h>
int main()
{
int range1,range2,i,j;
printf("Enter a range:");
scanf("%d %d", &range1, &range2);
printf("Strong numbers between %d and %d are: ",range1,range2);
for(i=range1;i<=range2;i++)
{
int num2=i;
int num1=i;
int sum=0;
int fact=1;
while(num1!=0)
{   fact=1;
int rem=num1%10;
num1=num1/10;
for(j=1;j<=rem;j++)
fact=fact*j;
sum=sum+fact;
}
if(sum==num2)
printf("%d ",i);
}
}

Input/Output:
Enter a range:
10
200
Strong numbers between 10 and 200 are: 145

Program in C++

Here is the source code of the C++ Program to print Strong numbers in a given range.

Code:

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

Input/Output:
Enter a range:
50
500000
Strong numbers between 50 and 500000 are: 145 40585

Program in Java

Here is the source code of the Java Program to Find out all primes numbers present within a given range.

Code:

import java.util.Scanner;
public class StrongNumberInRange {

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("Strong numbers between "+firstnumber+" and "+endnumber+" are:");
for(i=firstnumber;i<=endnumber;i++)
{
int num2=i;
int num1=i;
int sum=0;
int fact=1;
while(num1!=0)
{   fact=1;
int rem=num1%10;
num1=num1/10;
for(int j=1;j<=rem;j++)
fact=fact*j;
sum=sum+fact;
}
if(sum==num2)
System.out.println(i+" ");
}
cs.close();
}
}

Input/Output:
Enter the First number:
500
Enter the Last number:
100000000
Strong numbers between 500 and 100000000 are:
40585

Program in Python

Here is the source code of the Python Program to Find out all Strong numbers present within a given range.

Code:

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

Input/Output:
Enter a range:
10
70000000
Strong numbers between  10  and  70000000  are:
145 40585