Introduction

Control Statement

- Program to the sum of natural numbers
- Program to check leap year
- Program to find factorial of the number
- Program to find reverse of the number
- Program to Check Armstrong Number
- Program to find the sum of Natural Numbers using Recursion
- Calculator Program
- Program to identify day of week
- Program to print Fibonacci series

Function

- 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
- 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

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