Ask Question
30 March, 17:23

What is the output of the following function call? / /function body int factorial (int n) { int product=0; while (n > 0) { product = product * n; n❝; } return product; } / /function call cout << factorial (4);

+4
Answers (1)
  1. 30 March, 21:18
    0
    zero

    Explanation:

    Because of the define the product variable is zero.

    when the function call with pass by value 4.

    The program control moves to that function, after that product

    store the value zero. Then, product is multiply with n which become zero

    because 0 * n is zero and store in the product again.

    after that, n'' is wrong it must be 'n--' for performing the factorial function.

    after that, the value of n is 3, again loop execute because condition n > 0

    is true.

    again zero multiply with n and become zero.

    this process repeated until condition false and finally the output is zero.

    Correction:

    To make the code working:

    change product = 1 instead of zero.

    and change n- - in place of n''.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “What is the output of the following function call? / /function body int factorial (int n) { int product=0; while (n > 0) { product = ...” 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