Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Recursive Call Example Sum
// clang 3.8.0 // Example from Lecture 5 in class on recursive functions #include <iostream> using namespace std; int recursiveAdd(int n) { int returnValue; for (int i=0; i<10-n; i++) cout << " "; cout << "Entering into recursiveAdd: n = " << n << endl; if (n==1) { returnValue = 1; } else { returnValue = n + recursiveAdd(n-1); } for (int i=0; i<10-n; i++) cout << " "; cout << "Returning from recursiveAdd: n = " << n << " -- Ans = " << returnValue << endl; return returnValue; } int main() { int n, answer; cout << "Enter n: "; cin >> n; cout << endl << "n = " << n << endl << endl; answer = recursiveAdd(n); cout << endl << "Triangle sum of " << n << " = " << answer << endl; return 0; }
run
|
edit
|
history
|
help
0
std::function ambiguity clang
vector destruction - clang
hello,world !ssn2019
Maze problem solution
for_each_argument
LOOL
Math1
problem_name_4
HTML Timetable generator.cpp
Argument passing by using reference and value