Factorial of a number entered by User

Factorial :-

The factorial (represent with symbol: ! ) multiply all whole numbers from our chosen number down to 1.

The general formula of factorial can be written in fully expanded form as :-

n! = n x (n-1) x (n-2) x ...x 3 x 2 x 1.
or in partially expanded form as
n! = n  x (n-1)!.


Examples :-

1! = 1
3! = 3 x 2 x 1 = 6
4! = 4 × 3 × 2 × 1 = 24
7! = 7 × 6 × 5 × 4 × 3 × 2 × 1 = 5040
0! = 1

n! = n x (n-1)!
1! = 1 x (1-1)!
1! = 1 x (0)!

0!=must be equal to 1 then only it give the result as 1.

1! = 1

Implimentatin of factorial program:-



n =int(input("Enter the number to find factorial: "))
fact=1
if(n<0):
    print("Factorial is not possible for negative number! ")
elif(n==0 or n==1):
    print("The factorial of ",n," is ",fact)
else:
    for i in range(1,n + 1):
        fact = fact*i
    print("The factorial of ",n," is ",fact)

Comments

Popular posts from this blog

Display Browser information using javascript

Understanding Activation Functions in Deep Learning and Machine Learning

Understanding the Differences between POST, PUT, and PATCH in REST APIs