Find strong numbers between an interval
C program to find Strong Numbers within a range of numbers.
When the sum of the factorial of a number’s individual digits is equal to the number itself, then that number is called a strong number.
For example, Let num = 145
Sum of factorial of digits = 1! + 4! + 5! = 1 + 24 + 120 = 145
Hence, 145 is a strong number
Some of the strong numbers are: 1, 2, 145, 40585, ...
For example, Let num = 145
Sum of factorial of digits = 1! + 4! + 5! = 1 + 24 + 120 = 145
Hence, 145 is a strong number
Some of the strong numbers are: 1, 2, 145, 40585, ...
Program
#include<stdio.h>
#include<conio.h>
void main()
{
int low, high, i, j, k, fact, sum, temp;
printf("Enter two numbers (interval)\t:");
scanf("%d%d",&low,&high);
printf("Strong numbers between %d and %d are\t:",low,high);
for(k=low;k<=high;k++)
{
sum = 0;
temp = k;
while(temp > 0)
{
i = temp % 10;
fact = 1;
for(j=1;j<=i;j++)
{
fact = fact * j;
}
sum = sum + fact;
temp = temp / 10;
}
if(k == sum)
printf("%d, ",k);
}
getch();
}
Output
Enter two numbers (interval) :1
50000
Strong numbers between 1 and 50000 are :1, 2, 145, 40585,