Skip to content

Commit 20198fa

Browse files
Add recursive factorial function in question.py
Implement recursive function to calculate factorial.
1 parent 522592a commit 20198fa

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

12_Recursion/question.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
## Factorial of a number nikalne ke liye recursive function likho.
2+
3+
def factorial(n):
4+
if n == 0 or n == 1:
5+
return 1
6+
return n * factorial(n - 1)
7+
8+
print(factorial(5)) # Output: 120
9+
10+
## Har step me number ko uske previous number ke factorial se multiply karte hain.

0 commit comments

Comments
 (0)