You are given a number N. You have to find the number of operations required to reach N from 0. You have 2 operations available. - Codeprg

Breaking

programing News Travel Computer Engineering Science Blogging Earning

Sunday 24 May 2020

You are given a number N. You have to find the number of operations required to reach N from 0. You have 2 operations available.



You are given a number N. You have to find the number of operations required to reach N from 0. You have 2 operations available:

1.)Double the number
2.)Add one to the number
simple Recursive Approach with execution time 0.01s.


#include
using namespace std;

int solve(int n)
{
    if(n==0)
    return 0;
    else
    if(n%2==0)
    return solve(n/2)+1;
 
    return solve(n-1)+1;
}

int main() {
 
//code

int t;
cin>>t;
while(t--)
{
    int n;
    cin>>n;
    cout< }
return 0;
}