Given a number n, find sum of first n natural numbers. To calculate the sum, we will use a recursive function recur_sum().
Input : 3 Output : 6 Explanation : 1 + 2 + 3 = 6 Input : 5 Output : 15 Explanation : 1 + 2 + 3 + 4 + 5 = 15
Below is code to find the sum of natural numbers up to n using recursion :
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Difference between sum of the squares of first n natural numbers and square of sum
- Sum of series formed by difference between product and sum of N natural numbers
- Product of 2 Numbers using Recursion
- Product of 2 numbers using recursion | Set 2
- Print even and odd numbers in a given range using recursion
- Find ways an Integer can be expressed as sum of n-th power of unique natural numbers
- Sum of cubes of first n odd natural numbers
- Program to find sum of first n natural numbers
- Sum of array elements using recursion
- Sum of digit of a number using recursion
- Sum of array Elements without using loops and recursion
- Sum of the series 1^1 + 2^2 + 3^3 + ..... + n^n using recursion
- Sum of even elements of an Array using Recursion
- Find Maximum Level Sum in Binary Tree using Recursion
- Count of subsets with sum equal to X using Recursion
- Find geometric sum of the series using recursion
- Sum of N-terms of geometric progression for larger values of N | Set 2 (Using recursion)
- Decimal to Binary using recursion and without using power operator
- Print all increasing sequences of length k from first n natural numbers
- Find m-th summation of first n natural numbers.
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : jit_t