FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpp-programming/OOP1-Lab7/sum.cpp at main · Exzqqq/cpp-programming · GitHub
Exzqqq
/
cpp-programming
Public
forked from
Rustam-Z/cpp-programming
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cpp-programming
/
OOP1-Lab7
/
sum.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
17 lines (16 loc) · 546 Bytes
Breadcrumbs
cpp-programming
/
OOP1-Lab7
/
sum.cpp
Copy path
File metadata and controls
17 lines (16 loc) · 546 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#
include
<
iostream
>
using
namespace
std
;
long
long
int
sum
(
long
long
int
n) {
//
fuction called 'sum' foe calculating the sum of the natural numbers
if
(n ==
0
)
return
0
;
//
will return '0' when number will come to 0
else
return
n +
sum
(n -
1
);
//
using recursion
}
int
main2
() {
cout <<
"
\t\t\t
***Program to calculate the sum of natural numbers using recursion***
"
<< endl;
int
num;
cout <<
"
Please enter the interval:
"
;
cin >> num;
//
inpuing the interval of the numbers
cout<<
"
The sum is :
"
<<
sum
(num);
//
calling function 'sum'
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL