Anyone know how to do this question?
Use recursion to implement the following recurrence relation f(x):
f(x)=1 where =1
f(x) = f((x+1)/2) +1 where x is odd
f(x) = f(x/2) +1 where x is even
This is what i did:
#include<stdio.h>
int func (int x)
int main()
{
int x;
printf("Please enter the value of x: ");
scanf("%d", &x);
I changed the name of variable. Now it can compile but the outputs are incorrect?
For e.g. when i enter 12, i'm supposed to obtain 7. But the output was 5.
I enter 7, the output was 4 instead of 5.
Or am i missing out something?
Can someone explain to me?
Thanks!!