2,168 views
0 0 votes
#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;
}


(a) Stack Overflow (b) 3 (c) 4 (d) 5
 

5 Answers

0 0 votes

the above program having IF case without else condition simply solve using tree method.

0 0 votes

Start with small values....

F(1)=1

F(2)=F(1)=1

F(3)=F(1)+F(2)=1+1=2

F(11)=F(5)+F(6)=F(2)+F(3)+F(3)=1+2+2=5

Position:
Show:

Related questions

4 4 votes
1 1 answer
1.3k
1.3k views
1 1 vote
0 0 answers
2.1k
2.1k views
Na462 asked Jan 12, 2019
2,062 views
Number of times # will be printed on foo(7) ?
0 0 votes
2 2 answers
997
997 views
Prakhar Shukla 1 asked Dec 8, 2017
997 views
I am getting answer 13 but answer given is 17 !