Example
Input
Input number: 145
Output
145 is STRONG NUMBER
Strong number is a special number whose sum of factorial of digits is equal to the original number.
For example: 145 is strong number. Since, 1! + 4! + 5! = 145
/**
* C program to check whether a number is Strong Number or not
*/
#include <stdio.h>
int main()
{
int i, originalNum, num, lastDigit, sum;
long fact;
/* Input a number from user */
printf("Enter any number to check Strong number: ");
scanf("%d", &num);
/* Copy the value of num to a temporary variable */
originalNum = num;
sum = 0;
/* Find sum of factorial of digits */
while(num > 0)
{
/* Get last digit of num */
lastDigit = num % 10;
/* Find factorial of last digit */
fact = 1;
for(i=1; i<=lastDigit; i++)
{
fact = fact * i;
}
/* Add factorial to sum */
sum = sum + fact;
num = num / 10;
}
/* Check Strong number condition */
if(sum == originalNum)
{
printf("%d is STRONG NUMBER", originalNum);
}
else
{
printf("%d is NOT STRONG NUMBER", originalNum);
}
return 0;
}
/*
Output :
Enter any number to check Strong number: 145
145 is STRONG NUMBER
*/