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

Sagot :

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)

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)