C - Functions - Discussion

You Are Here :: Home > C > Functions - Discussion

 



Q.

What is the following function computing? Assume a and b are positive integers.

int fn( int a, int b) {
if (b == 0)
return b;
else
return (a * fn(a, b - 1));
}

A. Output will be 0 always B. Output will always be b
C. Computing ab D. Computing a + b

Answer: Option A
Explaination:

The output is always be 0 because b is decremented in recursive function fn each time by 1 till the terminating condition b==0 where it will return 0.



Discussion

Your Comments Goes here...
NameDiscussion