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.

Strong numbers in 1 to 100 in Cpp


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 
int main() {
    int i, n, n1, s1 = 0, j, k, en, sn;
    long fact;

    printf("Find Strong Numbers within an range of numbers:\n");
    /* If sum of factorial of digits is equal to original number then it is Strong number */
    sn = 1;
    en = 100;

    for (k = sn; k <= en; k++) {        
n1 = k;        
s1 = 0;      
 for (j = k; j > 0; j = j / 10) {            fact = 1;            for (i = 1; i <= j % 10; i++) {                fact = fact * i;            }            s1 = s1 + fact;        }        if (s1 == n1) printf("%d  ", n1);    }    printf("\n");    return 0; }
Find Strong Numbers within an range of numbers:
1 2