Computer Science, asked by mitanshu1619, 5 months ago

Write program to
find the factorial of a given number
Input N=5 then Output
5*4*3*2*1 =120​

Answers

Answered by yadav123pooja456
2

Answer:

n=int(input("enter no."))

f=1

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

f=f*i

print("factorial of number is",f)

Answered by anjalin
1

The given python program iteratively finds the factorial of the number given as input.

Explanation:

  • The given snippet firstly takes the number as input whose factorial is required.
  • Then the variable f is declared and initialized to 1.
  • Then the factorial is found out by iteratively multiplying the numbers.
  • Finally, after the iteration is completed, the final result is stored in the variable f.
  • The result is then displayed using the print command.

n = int ( input ( " enter no. " ) )

f=1

s=" "

for \hspace{0.2 cm}i \hspace{0.2 cm}in \hspace{0.2 cm}range(1, n+1):

        \hspace{0.5 cm} s + = str\hspace{0.02 cm}(i)+"*"

        \hspace{0.5 cm} f=f \cdot i

s+="="

print(s,f)

  • The image of the output given by the above snippet is attached below.
Attachments:
Similar questions