-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
34b6b51
commit 4fc8233
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
def factorial(n): | ||
if n==0 or n==1: | ||
return 1 | ||
return n* factorial(n-1) | ||
number=3 | ||
print(f"factorial of {number}:{factorial(number)}") | ||
|
||
|
||
|
||
def fibonacci(n): | ||
if n==0: | ||
return 0 | ||
if n==1: | ||
return 1 | ||
return fibonacci(n-1)+fibonacci(n-2) | ||
number=6 | ||
print(f"fibinocci of {number}:{fibonacci(number)}") | ||
|
||
|
||
def sum_of_digits(n): | ||
if n==0: | ||
return 0 | ||
return n%10+ sum_of_digits(n//10) | ||
number=1234 | ||
print(sum_of_digits(number)) | ||
|
||
|
||
def factorial_iterative(n): | ||
result = 1 | ||
for i in range(1, n + 1): | ||
result *= i | ||
return result | ||
number=5 | ||
print(factorial_iterative(number)) |