110k views
0 votes
Write a console application that takes an integer input from the user and calculates the factorial of it. Note: factorial of Example Input: 5 Example Output: 1^ * 2^ * 3^ * 4^ * 5=120

User Elfisher
by
3.8k points

1 Answer

3 votes

Answer:

The program in Python is as follows:

n = int(input("Integer: "))

product = 1

for i in range(1,n+1):

product*=i

if(i!=n):

print(str(i)+" *",end =" ")

else:

print(i,end =" ")

print(" = ",product)

Step-by-step explanation:

This prompts the user for integer input

n = int(input("Integer: "))

This initializes the product to 1

product = 1

This iterates through n

for i in range(1,n+1):

This multiplies each digit from 1 to n

product*=i

This generates the output string

if(i!=n):

print(str(i)+" *",end =" ")

else:

print(i,end =" ")

This prints the calculated product (i.e. factorial)

print(" = ",product)

User Jakentus
by
5.2k points