C++ Program For Sum of Natural Numbers Using Recursion Last Updated : 23 Jun, 2023 Comments Improve Suggest changes 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 Program to find Sum of the series 1*3 + 3*5 + .... 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 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 C++ Program To Find The Sum Of Last N Nodes Of The Given Linked List Given a linked list and a number n. Find the sum of the last n nodes of the linked list.Constraints: 0 <= n <= number of nodes in the linked list. Examples: Input: 10->6->8->4->12, n = 2 Output: 16 Sum of last two nodes: 12 + 4 = 16 Input: 15->7->9->5->16->14, n = 4 10 min read Program to find N-th term of the series a, b, b, c, c, c,....... Given a number N. The task is to write a program to find the N-th term in the below series: a, b, b, c, c, c, d, d, d, d, ..... Examples: Input : 12 Output : e Input : 288 Output : x The idea is to use AP sum formula to find the solution to this problem. Clearly the series is depicted as 1a, 2b's, 3 8 min read Like