- Related Questions & Answers
- Python Program to Check if a Number is a Strong Number
- C Program to find the given number is strong or not
- Write a C# program to check if a number is Palindrome or not
- Write a C# program to check if a number is prime or not
- Python program to check if a number is Prime or not
- Python Program to Find if a Number is Prime or Not Prime Using Recursion
- Write a Golang program to check whether a given number is prime number or not
- C program to find if the given number is perfect number or not
- Check if a number is an Achilles number or not in Python
- Program to check a number is ugly number or not in Python
- C# Program to check if a number is prime or not
- PHP program to check if a number is prime or not
- Check if a number is a Krishnamurthy Number or not in C++
- Bash program to check if the Number is a Prime or not
- Write a Golang program to check whether a given number is a palindrome or not

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

A Strong number is one that is equal to the sum of the factorial of its digits.

145 Factorial of 1=1 Factorial of 4=24 Factorial of 5=120 Sum=1+24+120 =145

Following program is to find if the input number is a strong number or not. Return ‘True’ if the number is a strong number, else return ‘False’.

We are using two functions

**isStrong()**which determines whether the number is strong or not, second method is**factorial()**which returns the factorial of the passed digit.The

**factorial()**is called from inside**isStrong()**to get factorials of all the digits(n%10) and add it to the sum.After factorial of all the digits are summed up, the sum is compared to the original number, if they are equal, true is returned, else false is returned.

*Why are we copying*On iterating through the while loop, the value of n will change to zero.But we require the original value to be compared with the sum later on and hence, we need to copy value of n into some variable before it is changed.**n**into**num**in**isStrong()**?The

**factorial()**uses recursion to calculate the factorial of the digits.

def factorial(d): if(d==1 or d==0): return 1 return d*factorial(d-1) def isStrong(n): num=n sm=0 while(n>0): digit=n%10 sm=sm+factorial(digit) n=n//10 if(sm==num): return True else: return False print("Input a number") a=int(input()) print(isStrong(a))

Input a number 145 True

Advertisements