# Write a program to compute the sum recursively in C++

# Program Sum Recursively in C++

**Object:** We can define the sum from 1 to x (i.e. 1 + 2 + … + x) recursively as follows for integer x ≥ 1: 1, if x = 1 x + sum from 1 to x-1 if x > 1 Write a program to compute the sum 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 recursively. C++ projects for beginners with source code

## Code:

**#include<iostream>**

**#include<conio.h>**

**using namespace std;**

**int readd(int nom);**

**void main()**

**{**

** int num;**

** cout<<“Enter any Positive Number: “;**

** cin>>num;**

** cout<<“Sum recursively: “<<readd(num);**

** getch();**

**}**

**int readd(int nom)**

**{**

** if(nom!=0)**

** {**

** return nom+readd(nom-1);**

** }**

** else**

** {**

** return nom;**

** }**

**}**

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #include<iostream> #include<conio.h> using namespace std; int readd(int nom); void main() { int num; cout<<"Enter any Positive Number: "; cin>>num; cout<<"Sum recursively: "<<readd(num); getch(); } int readd(int nom) { if(nom!=0) { return nom+readd(nom-1); } else { return nom; } } |

## 1 Response

[…] Write a program to compute the sum recursively in C++ […]