Question
What is the output of the following recursive function
call func(3) ? int func ( int n) { if (n == 0 ) return 1 ; return n * func(n - 1 ); }Solution
This function computes the factorial of n . Factorial is defined as n!=n×(n−1)× ⋯ ×1 . For n=3 :
- func(3) calls 3 * func(2) .
- func(2) calls 2 * func(1) .
- func(1) calls 1 * func(0) .
- func(0) returns 1 (base case).
- Option A (1): Only the base case returns 1 . This does not account for recursive multiplication.
- Option B (3): This is the input but not the factorial result.
- Option D (9): This result might confuse with 3² , which is unrelated to factorial.
- Option E (27): This is 3^3 .
An object is placed at the principal focus of a concave lens. Which of the following options represents the characteristics of the image formed?
The Factories Act, 1948 prohibits the employment of young persons under the age of ______ years.
Under the provision of ‘The Code on Wages, 2019’, which of the following is true regarding imposition of fine by the employer?
1. Every fin...
Which of the following properties do covalent compounds generally NOT exhibit?
Which of the following option is incorrect regarding the “Mahila Samman Savings Certificate”?
Which of the following is incorrect regarding “PM Ujjwala Yojana”?
Which state is the largest contributor to India’s total natural rubber production?
The only Sultan of Delhi to conquer Chittor, the capital of Mewar was
Which of the following is not a positive aspect of globalization?
Which section of the cash flow statement reports the cash inflows and outflows related to investing activities?