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 .
The following statements relate to the election of Indian President. Find out the wrong statement.
Rajasthani Language Day' is celebrated on-
Who formed the association in favour of widow remarriage in Madras Presidency?
Heat received by earth from the Sun is known as
Who introduced the Permanent Settlement of Bengal?
The statements of estimated receipts and expenditure of the Government of India is presented to the Parliament every year as per ____of the Indian Const...
The hill at Bairath, where the remains of the Buddhist Vihara have been found, is known as-
Which among the following book was not written by Krishnadev Raya?
The Mughal Emperor who gave permission to East India Company to set up trading post at Surat?
Which one of the following constituents of the atmosphere causes greatest changes in climate and weather?