in Algorithms recategorized by
604 views
1 vote
1 vote

Consider the following program. Assume that $x$ and $y$ are integers.

f(x, y)
{
    if (y != 0)
        return (x * f(x,y-1));
    else
        return 1;
}

What is $f(6,3)?$

  1. $243$
  2. $729$
  3. $125$
  4. $216$
in Algorithms recategorized by
604 views

2 Answers

0 votes
0 votes
Solution: (D) is correct. This code computes $x^y$. f(6,3) will compute $6^3$ which is 216.
0 votes
0 votes

 The given code computes the value of $6^3 =216$.

So Option $(D)$ is correct.

edited by
Answer:

Related questions