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 growth regulators are used for increasing curcumin content in turmeric rhizomes?
How many pollen grains are developed from a pollen mother cell?
When something in the landscape is repeated with a standard interval, it is called
Which technique uses double stranded RNA (dsRNA) as a trigger that targets homologous mRNAs for degradation or inhibiting its transcription translation?
Which reptile is characterized by the presence of four-chambered heart?
The effective post-emergence control of Ageratum houstonianum can be achieved with
Cell is the fundamental structural and functional unit of all living organisms. It was first discovered by ____
Installing 10-12 blue/yellow sticky traps per hectare is effective to manage: -
Chlorophyll.a,usually appears:Â
A farmer can become an entrepreneur by