Skip to content

Commit 597dfb8

Browse files
authored
Python Program for factorial of a number
Factorial of a non-negative integer, is multiplication of all integers smaller than or equal to n. For example factorial of 6 is 6*5*4*3*2*1 which is 720.
1 parent f581e7e commit 597dfb8

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

factorial

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
def factorial(n):
2+
if n < 0:
3+
return 0
4+
elif n == 0 or n == 1:
5+
return 1
6+
else:
7+
fact = 1
8+
while(n > 1):
9+
fact *= n
10+
n -= 1
11+
return fact
12+
13+
# Driver Code
14+
num = 5;
15+
print("Factorial of",num,"is",
16+
factorial(num))

0 commit comments

Comments
 (0)