# How to write a c++ program to find the sum of natural numbers using recursion

How to write a __c++ program__ to find the sum of natural numbers using recursion. In this program, you will learn how to find the sum of natural numbers using recursion.

Take an example to find the sum through a __c++ program__:

```
// How to write a c++ program to find
// the sum of natural numbers using recursion
#include <bits/stdc++.h>
using namespace std;
int recSum(int x);
int main() {
int x;
// x - dnotes a positive number
cout << "-----Enter a positive number to get the sum-----\n";
cin >> x;
cout << "\nThe Sum is: " << recSum(x) << "\n";
return 0;
}
int recSum(int n) {
if (n)
return n + recSum(n - 1);
else
return n;
}
```

**Output:**

`-----Enter a positive number to get the sum-----`

22

`The Sum is: 253`

## Tags:

# how to write a c++ program to find factorial of a number using recursion

# how to write a c++ program to print n natural numbers using recursion

# how to write a program in c++ to calculate the sum of numbers from 1 to n using recursion.