write a program to check whether a number is Peterson or not.
Answer Posted / prasanna kumar
N = int(input("Enter a number: "))
original_num = N
sum_of_factorials = 0
while N > 0:
digit = N % 10
fact = 1
for i in range(1, digit + 1):
fact = fact * i
sum_of_factorials = sum_of_factorials + fact
N = N // 10
if sum_of_factorials == original_num:
print(f"{original_num} is a Peterson number")
else:
print(f"{original_num} is not a Peterson number")
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
Explain what is a static function?
How can I manipulate individual bits?
Write a program to know whether the input number is an armstrong number.
What are shell structures used for?
What are the characteristics of arrays in c?
Write a code to remove duplicates in a string.
what will be the output for the following main() { printf("hi" "hello"); }
How to implement a packet in C
What does sizeof function do?
Explain how many levels deep can include files be nested?
Are the outer parentheses in return statements really optional?
What are the different categories of functions in c?
Why main is used in c?
What is a program?
can any one please explain, how can i access hard disk(physical address)? it is possible by the use of far,near or huge pointer? if yes then please explain......