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 .
Which of the following statements about Subrahmanyam Jaishankar is/are correct?
(1) He was the then India’s ambassador to United State of Ameri...
Who was the first Odissi dancer from Odisha to receive Padma Vibhushan?
 Japan's 2+2 dialogue with India involves which two Indian ministries?
What is the maximum compensation that can be awarded by the Banking Ombudsman under the Reserve Bank of India's scheme?
Which of the following is correct in regards to the major schemes and their respective fund allocations for the fiscal year 2024-2025, as outlined in th...
Which institution are mandated to open at least one RSETI in their lead district to provide training to rural youth to take up self-employment/ entrepr...
Which of the following is NOT a Small Finance Bank (SFB)?
The nodal coordinating agency for the Project ‘PARI’ of the Ministry of Culture is
Which of the following won the 'NATIONAL TECHNOLOGY AWARD (MAIN)' in National Technology Week 2023?
Who was the writer of ‘Ain-i-Akbari’?