How to reduce an additional argument in recursion | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to reduce an additional argument in recursion

Please find below code: Both the code working fine. Using stack and recursion one. Query is to eliminate the first argument of the recursive function.. can we do same thing without having additional argument called int original ? I am confused what should be base case without the original argument value ? https://code.sololearn.com/ccYvDpokBzOb/?ref=app

21st Apr 2022, 2:19 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
2 Answers
+ 2
Recall that each program comes with a stack: the call stack. Entering a function is like .push, leaving a function is like .pop :) void displaySeries(int n, int m) { if (n < 0) return; cout << n << ", "; displaySeries(n-m, m); cout << n << ", "; }
21st Apr 2022, 2:31 PM
Schindlabua
Schindlabua - avatar
0
Yeah..thanks
21st Apr 2022, 2:35 PM
Ketan Lalcheta
Ketan Lalcheta - avatar