Sunday, 4 December 2016

factorial of number



#factorial of number

#In mathematics, the factorial of a non-negative integer n, denoted by n!.
#It is the product of all positive integers less than or equal to n.

#to accept number from user
n=int(input('enter no:'))

#initiating variable
fact=1

#defining conditions
if(n<0):
    print('factorial of no. cannot be calculated')
elif(n==0):
    print("factorial of 0 is 1")
else:
    for i in range(1,n+1):
        fact=fact*i
    print('The factorial of', n , 'is' ,fact)

OUTPUT:

No comments:

Post a Comment