C Program to Find Sum of Natural Numbers using Recursion Last Updated : 08 Jun, 2023 Comments Improve Suggest changes 4 Likes Like Report Natural numbers include all positive integers from 1 to infinity. There are multiple methods to find the sum of natural numbers and here, we will see how to find the sum of natural numbers using recursion. Example Input : 5Output : 15Explanation : 1 + 2 + 3 + 4 + 5 = 15 Input : 10Output : 55Explanation : 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = 55 ApproachGiven a number n, To calculate the sum, we will use a recursive function recSum(n).BaseCondition: If n<=1 then recSum(n) returns the n. Recursive call: return n + recSum(n-1).Program to find the sum of Natural Numbers using Recursion Below is the implementation using recursion: C // C program to find the sum of n // natural numbers using recursion #include <stdio.h> // Returns the sum of first n // natural numbers int recSum(int n) { // Base condition if (n <= 1) return n; // Recursive call return n + recSum(n - 1); } // Driver code int main() { int n = 10; printf("Sum = %d ", recSum(n)); return 0; } OutputSum = 55 The complexity of the above method Time complexity: O(n). Auxiliary space: O(n). Comment M mukulsomukesh Follow 4 Improve M mukulsomukesh Follow 4 Improve Article Tags : C Programs C Language C Basic Programs Explore C BasicsC Language Introduction6 min readIdentifiers in C3 min readKeywords in C2 min readVariables in C4 min readData Types in C3 min readOperators in C8 min readDecision Making in C (if , if..else, Nested if, if-else-if )7 min readLoops in C6 min readFunctions in C5 min readArrays & StringsArrays in C4 min readStrings in C5 min readPointers and StructuresPointers in C7 min readFunction Pointer in C6 min readUnions in C3 min readEnumeration (or enum) in C5 min readStructure Member Alignment, Padding and Data Packing8 min readMemory ManagementMemory Layout of C Programs5 min readDynamic Memory Allocation in C7 min readWhat is Memory Leak? How can we avoid?2 min readFile & Error HandlingFile Handling in C11 min readRead/Write Structure From/to a File in C3 min readError Handling in C8 min readUsing goto for Exception Handling in C4 min readError Handling During File Operations in C5 min readAdvanced ConceptsVariadic Functions in C5 min readSignals in C language5 min readSocket Programming in C8 min read_Generics Keyword in C3 min readMultithreading in C9 min read Like