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
lref assignment
Thread-safe Interval Average Calculator
test
chakib
Tilted uniform distribution random number generator over min/max range
MPL 2-1
Standard Template Library
CS1428 SI Tuesday
List comprehension in C++ using functional patterns
BucketSort