Ask Question

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

+2
Answers (1)
  1. 26 February, 04:29
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers