- 0
Notifications Mark All Read
- Login
- Get Prime
Strong numbers in 1 to 100 in C
Strong Number in 1 to 100
Today in this page we will be discussing the code to find the Strong Numbers from 1 to 100 in C programming language.
Strong number is a special number whose sum of the factorial of digits is equal to the original number.
For Example: 145 is strong number. Since, 1! + 4! + 5! = 145.
Let’s understand what is strong number with the help of some examples
Input: N = 100
Output: 1 2
Explanation:
Only 1 and 2 are the strong numbers from 1 to 100 because
1! = 1, and
2! = 2
Input: N = 1000
Output: 1 2 145
Explanation:
Only 1, 2 and 145 are the strong numbers from 1 to 1000 because
1! = 1,
2! = 2, and
(1! + 4! + 5!) = 145
Strong numbers in 1 to 100 in C
Run
#include <stdio.h> #include <stdlib.h> int factorial (int f) { int mul = 1; for (int i = 1; i <= f; i++) { mul = mul * i; } return mul; } int main () { int fact = 1, sum = 0; int n, r; n = 200; printf ("Strong numbers are :"); for (int i = 1; i <= n; i++) { int k = i; while (k != 0) { r = k % 10; fact = factorial (r); k = k / 10; sum = sum + fact; } if (sum == i) { printf ("%d, ", i); } sum = 0; } return 0; }
All Strong numbers between 1 to 100 are:
1, 2,
Login/Signup to comment