diff --git a/algorithms/Python/README.md b/algorithms/Python/README.md index bc9438e9..f3fb531a 100644 --- a/algorithms/Python/README.md +++ b/algorithms/Python/README.md @@ -25,6 +25,7 @@ - [Factorial](recursion/factorial.py) - [n-th Fibonacci number](recursion/nth_fibonacci_number.py) - [Recursive Insertion Sort](recursion/recursive_insertion_sort.py) +- [Recursive Sum of n numbers](recursion/recursive-sum-of-n-numbers.py) ## Scheduling - [Interval Scheduling](scheduling/interval_scheduling.py) diff --git a/recursive-sum-of-n-numbers.py b/recursive-sum-of-n-numbers.py new file mode 100644 index 00000000..9e7014ac --- /dev/null +++ b/recursive-sum-of-n-numbers.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))