139k views
1 vote
4) Write a program which prints all Strong numbers within a range (say starting limit is 1 and ending limit is 1000; limits entered by the user). Use loops to solve this problem. Strong number is a special positive number (consider base 10 ) whose sum of the factorial of digits is equal to the eriginal number. For example, 145 is a Strong number because the sum of factorial of its digits 1!+4!+5 ! is: 145(1+24+120). [Write the full code.]

User Malartre
by
7.9k points

1 Answer

3 votes

Final answer:

To identify Strong numbers within a range, a program can be written in Python with a function to check if a number is a Strong number and a loop through the user input range to check each number.

Step-by-step explanation:

To find all Strong numbers within a user-defined range, one can write a program in Python using loops and functions. A Strong number is defined as a number that is equal to the sum of the factorial of its digits. For instance, 145 is a Strong number because 1! + 4! + 5! equals 145.

Here's a Python program to achieve this:

import math

def is_strong_number(num):
sum_factorial = 0
temp_num = num
while temp_num > 0:
digit = temp_num % 10
sum_factorial += math.factorial(digit)
temp_num //= 10
return sum_factorial == num

start_limit = int(input("Enter the start limit: "))
end_limit = int(input("Enter the end limit: "))

print("Strong numbers between", start_limit, "and", end_limit, ":")
for num in range(start_limit, end_limit + 1):
if is_strong_number(num):
print(num)

One should input the desired range and the program will output all the Strong numbers within that range.

User Jkp
by
8.3k points