C Programming Code Examples C > For Loops and While Loops Code Examples C program to print strong numbers between 1 to n C program to print strong numbers between 1 to n Write a C program to print Strong numbers between 1 to n. C program to print all strong numbers between a given range. Logic to print strong numbers in a given range in C program. What is a 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 Logic to print Strong numbers between 1 to n Input upper limit to print strong number from user. Store it in a variable say end. Run a loop from 1 to end, increment 1 in each iteration. Structure of the loop should be similar to for(x=1; x<=end; x++). For each iteration inside loop check x for strong number. Print the value of x if it is a strong number. #include <stdio.h> int main() { int x, j, cur, lastDigit, end; long long fact, sum; /* Input upper limit from user */ printf("Enter upper limit: "); scanf("%d", &end); printf("All Strong numbers between 1 to %d are:\n", end); /* Iterate from 1 to end */ for(x=1; x<=end; x++) { /* Number to check for strong number */ cur = x; sum = 0; /* Find the sum of factorial of digits */ while(cur > 0) { fact = 1ll; lastDigit = cur % 10; /* Find factorial of last digit of current num. */ for( j=1; j<=lastDigit; j++) { fact = fact * j; } sum += fact; cur /= 10; } /* Print 'x' if it is strong number */ if(sum == x) { printf("%d, ", x); } } return 0; }