Ask Question
26 October, 02:26

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);

+2
Answers (1)
  1. 26 October, 04:57
    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?
Find 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 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