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
bank queue
Peregruzka
the usual name hiding rules do apply with using directives
CS1428 SI Tuesday
even number
my override
Wrapper to pass shared_ptr to &, const &, *, const * through std::bind.
simple in-memory b-tree
Tree Example
move_string