Ask Question
19 December, 18:16

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

+1
Answers (1)
  1. 19 December, 20:12
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers