C++ Program For Sum of Natural Numbers Using Recursion Last Updated : 23 Jun, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report Natural numbers include all positive integers from 1 to infinity. It does not include zero (0). Given a number n, find the sum of the first n natural numbers. To calculate the sum, we will use the recursive function recur_sum(). Examples: Input: 3Output: 6Explanation: 1 + 2 + 3 = 6 Input: 5Output: 15Explanation: 1 + 2 + 3 + 4 + 5 = 15 The Sum of Natural Numbers Using Recursion Below is a C++ program to find the sum of natural numbers up to n using recursion: C++ // C++ program to find the sum // of natural numbers up to n // using recursion #include <iostream> using namespace std; // Returns sum of first // n natural numbers int recurSum(int n) { if (n <= 1) return n; return n + recurSum(n - 1); } // Driver code int main() { int n = 5; cout << recurSum(n); return 0; } Output15 Comment More infoAdvertise with us Next Article C++ Program For Sum of Natural Numbers Using Recursion K kartik Follow Improve Article Tags : C++ Programs C++ C++ Basic Programs Practice Tags : CPP Similar Reads C++ Program To Find Sum of First N Natural Numbers Natural numbers are those positive whole numbers starting from 1 (1, 2, 3, 4, ...). In this article, we will learn to write a C++ program to calculate the sum of the first N natural numbers. AlgorithmInitialize a variable sum = 0.Run a loop from i = 1 to n.Inside the loop, add the value of i to the 1 min read Sum of array Elements without using loops and recursion Given an array of N elements, the task is to find the Sum of N elements without using loops(for, while & doWhile) and recursion.Examples: Input: arr[]={1, 2, 3, 4, 5} Output: 15 Input: arr[]={10, 20, 30} Output: 60 j Approach: Unconditional Jump Statements can be used to solve this problem.Uncon 5 min read C++ Program For Finding Subarray With Given Sum - Set 1 (Nonnegative Numbers) Given an unsorted array of non-negative integers, find a continuous subarray that adds to a given number. Examples : Input: arr[] = {1, 4, 20, 3, 10, 5}, sum = 33 Output: Sum found between indexes 2 and 4 Sum of elements between indices 2 and 4 is 20 + 3 + 10 = 33 Input: arr[] = {1, 4, 0, 0, 3, 10, 5 min read C++ Program For Fibonacci Numbers The Fibonacci series is the sequence where each number is the sum of the previous two numbers. The first two numbers of the Fibonacci series are 0 and 1, and they are used to generate the entire series.Examples:Input: 5Output: 5Explanation: As 5 is the 5th Fibonacci number of series 0, 1, 1, 2, 3, 5 5 min read Program to find Sum of the series 1*3 + 3*5 + .... Given a series: Sn = 1*3 + 3*5 + 5*7 + ... It is required to find the sum of first n terms of this series represented by Sn, where n is given taken input.Examples: Input : n = 2 Output : S<sub>n</sub> = 18Explanation:The sum of first 2 terms of Series is1*3 + 3*5= 3 + 15 = 18Input : n = 8 min read Like