Predict the output of following program
#include <stdio.h>
int f(int n)
{
if(n <= 1)
return 1;
if(n%2 == 0)
return f(n/2);
return f(n/2) + f(n/2+1);
}
int main()
{
printf("%d", f(11));
return 0;
}
Now following calls will be made:
f(11) = f(5) + f(3) i.e 2+2=4
f(5) = f(2) + f(1) i.i. 1+1 =2
f(3) = f(1) + f(1) i.e. 1+1=2
f(2) = f(1) =1
Hence ans =4