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 .
Find the wrong no in the given number series.
175, 319, 488, 694, 909, 1165
2824 2314 1973 1759 1634 1574
Find the wrong number in given number series.
7, 8, 27, 215,997, 8988.
- Find the wrong number in the given number series.
8, 12, 21, 46, 95, 195 1648, 1690, 1741, 1807, 1938, 2140
Direction: Find the wrong number in given number series.
214, 230, 294, 550, 1574 , 5470.
- Find the wrong number in the given number series.
32, 48, 80, 108, 162, 243 Find the wrong number in given number series.
2482, 2507, 2607, 2842, 3232, 3857
Find the wrong number in the given number series.
84, 120, 183, 246, 336, 444
5, 6, 8, 16, 38, 158