Example
Input
Input number: 145
Output
145 is STRONG NUMBER
Required knowledge
Basic C programming, If else, For loop, While loop, Nested loop
What is 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 check Strong number
Step by step descriptive logic to check strong number.
- Input a number from user to check for strong number. Store this in a variable say num. Copy it to a temporary variable for calculations purposes, say
originalNum = num
.
- Initialize another variable to store sum of factorial of digits, say
sum = 0
.
- Find last digit of the given number num. Store the result in a variable say
lastDigit = num % 10
.
- Find factorial of lastDigit. Store factorial in a variable say fact.
- Add factorial to sum i.e.
sum = sum + fact
.
- Remove last digit from num as it is not needed further.
- Repeat steps 3 to 6 till
num > 0
.
- After loop check condition for strong number. If
sum == originalNum
, then the given number is Strong number otherwise not.
Learn more - Program to find sum of digits of number.