TheAlgorithms-C/misc/strong_Number.c

39 lines
582 B
C
Raw Normal View History

2017-07-13 08:09:15 +08:00
/**
* Modified on 07/12/2017, Kyler Smith
*
2020-04-08 21:41:12 +08:00
* A number is called strong number if sum of the
2017-07-13 08:09:15 +08:00
* factorial of its digit is equal to number itself.
*/
2020-04-08 21:41:12 +08:00
#include <stdio.h>
2017-07-13 08:09:15 +08:00
void strng(int a)
{
2020-04-08 21:41:12 +08:00
int j = a;
int sum = 0;
int b, i, fact = 1;
while (a > 0)
{
2020-04-08 21:41:12 +08:00
fact = 1;
b = a % 10;
for (i = 1; i <= b; i++)
{
2020-04-08 21:41:12 +08:00
fact = fact * i;
}
2020-04-08 21:41:12 +08:00
a = a / 10;
sum = sum + fact;
}
2020-04-08 21:41:12 +08:00
if (sum == j)
printf("%d is a strong number", j);
else
2020-04-08 21:41:12 +08:00
printf("%d is not a strong number", j);
}
2020-04-08 21:41:12 +08:00
int main()
{
int a;
printf("Enter the number to check");
2020-04-08 21:41:12 +08:00
scanf("%d", &a);
strng(a);
2020-04-08 21:41:12 +08:00
return 0;
}