-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path_72Sum_Recursion.cpp
More file actions
49 lines (37 loc) · 817 Bytes
/
_72Sum_Recursion.cpp
File metadata and controls
49 lines (37 loc) · 817 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
using namespace std;
int Sum(int number)
{
if (number == 0)
{
return 0;
}
else
{
int sum = 0;\
return sum = number + Sum(number-1);
}
}
int main()
{
int num;
int S;
char choice;
do
{
cout << "Enter a number: ";
cin >> num;
cout << "***********************************\n\n";
S = Sum(num);
cout << "The sum of first " << num << " is: " << S << endl;
cout << "***********************************\n";
cout << "Do you want to enter again? Y/N: ";
cin >> choice;
if (choice == 'n' || choice == 'N')
{
break;
}
} while (choice == 'y' || choice == 'Y');
cout << "Thankyou User\nThe program is over :)";
return 0;
}