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.
Example
Input
Input upper limit: 1000
Output
Strong numbers between 1-1000: 1, 2, 145
Required knowledge
Basic C programming, If satement, For loop, Nested loop
Must know –
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
Step by step descriptive logic to print strong numbers from 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(i=1; i<=end; i++)
. - For each iteration inside loop check i for strong number. Print the value of i if it is a strong number.
Let us convert the above logic to a C program.
Program to print strong numbers between 1 to n
Once, you got the logic of printing strong numbers between 1 to n. You can easily modify the logic to find strong numbers in any given range. Below program illustrates how to print strong numbers in a given range.
Program to print strong numbers in given range
Output
Enter lower limit: 1 Enter upper limit: 100000 1, 2, 145, 40585,
Happy coding