C Program to Check Strong Number
Strong numbers are those numbers whose sum of factorial of each digits is equal to the original number. For example 1 is strong number because 1!=1, 2 is strong number i.e. 2! = 2, 145 is strong number i.e. 1! + 4! + 5! = 1 + 24 + 120 = 145 etc.
C Source Code: Strong Number
#include<stdio.h>
int main()
{
int number, original, rem, sum=0, fact, i;
printf("Enter number: ");
scanf("%d", &number);
original = number;
/* Finding sum */
while(number != 0)
{
rem = number%10;
/* Finding Factorial */
fact = 1;
for(i=1; i<=rem; i++)
{
fact = fact*i;
}
sum = sum + fact;
number = number/10;
}
/* Making decision */
if(sum == original)
{
printf("%d is STRONG.", original);
}
else
{
printf("%d is NOT STRONG.", original);
}
return(0);
}
Output of the above program :
Run 1: ---------- Enter number: 145 ↲ 145 is STRONG. Run 2: ---------- Enter number: 2 ↲ 2 is STRONG. Run 3: ---------- Enter number: 123 ↲ 123 is NOT STRONG. Note: ↲ indicates enter is pressed.