Advertisements
Advertisements
Question
The following function int solve() is a part of some class. Assume ‘m’ and ‘n’ are positive integers. Answer the question given below with dry run/working.
int solve(int m, int n)
{
int k=1;
if(m<0)
return −k;
else if(m==0)
return m;
else
return k+(solve(m−n, n+2));
}
What is the function solve() performing apart from recursion?
Very Short Answer
Advertisements
Solution
The function counts steps while gradually decreasing m as n increases, with the exception of recursion.
shaalaa.com
Is there an error in this question or solution?
2024-2025 (March) Official Board
