Strong Number in C
Here you will know about strong number and get the program source code of strong number in c programming.
What is Strong Number in C
Strong number is one that is the sum of the factorials of all of its digits.
For example: 145 is a strong number
Factorial of 1 = 1
Factorial of 4 = 24
Factorial of 5 = 120
1 + 24 + 120 = 145 Therefore, 145 is a strong number.
Strong Number in C program
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | #include <stdio.h> int facto(int num) { int i=1, fact = 1; while(i<=num) { fact = fact * i; i++; } return fact; } int main() { int num, r, sum = 0, temp; printf("Enter a number: "); scanf("%d", &num); temp = num; while (temp > 0) { r = temp % 10; sum = sum + facto(r); temp = temp / 10; } if (sum == num) printf("%d is strong number.", num); else printf("%d is not strong number.", num); return 0; } |
Output 1
Enter a number: 40585
40585 is strong number.
Output 2
Enter a number: 158
158 is not strong number.
Check out our other C programming Examples