int C(int n, int k)
{
if (k= =0) return 1;
else return (C(n-1, k-1) * n)/k;
}
What type of function is this? Recursive or Iterative. Explain your answer.
This is a recursive function.
Explanation:
By definition recursive function is one which call itself. A recursive method solves a problem by calling a copy of itself to work on a smaller problem. We can see here, in the function C, it calls itself by the step " (C(n-1, k-1) * n)/k; " . So definitely it is a recursive function.
But an iterative function is one that repeat some parts its code again and again by means of loop. In your function there is no loop ( ie for loop or while loop or do while or foreach etc etc.)
Get Answers For Free
Most questions answered within 1 hours.