Recursion

AP Computer Science A· difficulty 3/5

Factorial: <code>int fact(int n)</code> =

  • A

    if (n <= 1) return 1; else return n * fact(n - 1);

    check_circle
  • B

    while (n > 1) ...

  • C

    Both A and B work; A is recursive

  • D

    for (int i = 1; i <= n; i++) ...

Explanation

Classic recursion: base case n ≤ 1; recursive call decreases n.

Want 10 more like this — adaptive to your weak spots?

Related questions

AP Computer Science A · Recursion Practice Question | Acemy