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 .
What is the nature of an award made by a Lok Adalat?
As per the Consumer Protection Act, who can appeal against an order made by the National Commission, and what is the time limit for filing such an appeal?
What is the time limit for making an arbitral award in matters other than international commercial arbitration, and what is the provision for internati...
On which date did the Bharatiya Sakshya Adhiniyam, 2023 receive Presidential assent?Â
Under the Code of Civil Procedure, 1908, which of the following statement is not correct?
Which of the following is true with respect to issue of shares at a discount?
Which section of the Arbitration and conciliation act, 1996 limits judicial intervention in arbitral proceedings?
How can the Comptroller and Auditor General of India (CAG) be removed from office?
What is the composition of the Central Information Commission under the RTI Act?
As per theBharatiya Nyaya Sanhita, what is the punishment for dishonestly or fraudulently concealing or removing property?