chore(Python): add sum of n numbers using recursion (#770)
parent
f1debdc7c3
commit
c780f5a641
|
@ -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)
|
||||||
|
|
|
@ -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))
|
Loading…
Reference in New Issue