Skip to content

Commit 1c02f15

Browse files
committed
Added iterative approach
1 parent aa3bd48 commit 1c02f15

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Programs/P09_Factorial.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ def factorial(number):
88
else:
99
return number * factorial(number - 1)
1010

11+
def factorial_without_recursion(number):
12+
fact = 1
13+
while(number > 0):
14+
fact = fact * number
15+
number = number - 1
16+
print('Factorial of', number,'is: ')
17+
print(fact)
18+
1119
if __name__ == '__main__':
1220
userInput = int(input('Enter the number to find its factorial: '))
13-
print('Factorial of',userInput,'is:',factorial(userInput))
21+
print('Factorial of', userInput, 'is:', factorial(userInput))
22+
factorial_without_recursion(userInput)

0 commit comments

Comments
 (0)