Ask Question
26 April, 23:42

For the question below, refer to the following recursive factorial method.

public int factorial (int x)

{

if (x > 1)

return x * factorial (x - 1);

else

return 1;

}

What is returned if factorial (3) is called?

a) 0

b) 1

c) 3

d) 6

e) 9

+4
Answers (1)
  1. 27 April, 00:43
    0
    (d) 6

    Explanation:

    When we call factorial (3) first it will check if it greater than 1 since it is greater then return 3*factorial (2) will be called on factorial (2) it will again check that 2>1 since it is greater then return 2*factorial (1) will be called. In factorial (1) we have is not greater than 1 so it will return 1. return 2*factorial (1) will return 2 and 2 that is returned by factorial (2) will be multiplied with 3. So it will return 6.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “For the question below, refer to the following recursive factorial method. public int factorial (int x) { if (x > 1) return x * factorial ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers