Introduction

Control Statement

- Program to find the sum of Natural Numbers using Recursion
- Calculator Program
- Program to identify day of week
- Program to print Fibonacci series
- Check Whether the Number is Even or Odd in C++
- Program to check whether the number is prime or not
- Program to check vowel or constant
- Program to check the largest number among three numbers
- Program to the sum of natural numbers

Function

- Program to find LCM
- Program to check prime number using Functions
- Program to convert Binary to Decimal Number
- Program to convert Decimal to Binary Number
- Program to convert Binary to Octal Number
- Program to convert Octal to Binary Number
- Program to find reverse of the sentence using Recursion
- Program to Shutdown and restart Computer
- Program to find the area of triangle

Array

Pointer

OOPS

No Examples found for this topic - CodeHelpPro

# Program to find the sum of Natural Numbers using Recursion

In this example, We will learn to find the sum of natural numbers using recursion.

To understand this examples, You must have knowledge in following topics.

```
#include<iostream>
using namespace std;
int add(int n);
int main() {
int n;
cout << "Enter a positive integer: ";
cin >> n;
cout << "Sum = " << add(n);
return 0;
}
int add(int n) {
if(n != 0)
return n + add(n - 1);
return 0;
}
```

The output of above program is

```
Enter a positive integer: 5
Sum = 15
```

Subscribe

Login

0 Comments

Inline Feedbacks

View all comments