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 .
If P(A ∪ B) = 0.75 and P(A ∩ B) = 0.3, then the value of P(Aᶜ) + P(Bᶜ) is:
A, B and C started a online education website by investing Rs.30,000, Rs.45,000 and Rs.60,000 respectively. Find the share of A’s, out of an annual pr...
17, 16, 34, 32, 68, 66
A rectangle has a perimeter of 60 cm, and the ratio of its length to its width is 3:2. Find the length of its diagonal.
67.2, 8.4, 1.2, 0.2, 0.04, ?
Aman bought 21 notebooks for Rs.1250 from shop A and 12 notebooks for Rs.895 from shop B. What is the average price he paid per book?
A and B together can complete a task in 12 days. B alone can complete it in 20 days. How long will it take A to complete the task if he works alone?
Determine the area of an equilateral triangular field having perimeter of 42m.
A person sells two items, X and Y. The marked prices of X and Y are 25% and 40% higher than their cost prices, respectively. After a 10% discount on bot...