chore(Python): add sum of n numbers using recursion (#770)

pull/774/head
Anika Kamath 2022-07-09 21:01:28 +05:30 committed by GitHub
parent f1debdc7c3
commit c780f5a641
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -25,6 +25,7 @@
- [Factorial](recursion/factorial.py) - [Factorial](recursion/factorial.py)
- [n-th Fibonacci number](recursion/nth_fibonacci_number.py) - [n-th Fibonacci number](recursion/nth_fibonacci_number.py)
- [Recursive Insertion Sort](recursion/recursive_insertion_sort.py) - [Recursive Insertion Sort](recursion/recursive_insertion_sort.py)
- [Recursive Sum of n numbers](recursion/recursive-sum-of-n-numbers.py)
## Scheduling ## Scheduling
- [Interval Scheduling](scheduling/interval_scheduling.py) - [Interval Scheduling](scheduling/interval_scheduling.py)

View File

@ -0,0 +1,12 @@
def recsum(n):
if n<=1:
return(n)
else:
return(n+recsum(n-1))
n= 15
if n<0:
print("Enter a positive integer")
else:
print("Sum =",recsum(n))