hello, What is the code for this C program or logic?
Given a number N the task is to find an optimal solution to reach N
using two operations only. First option is operation 0: Double the
number and second option is operation is 1: Add one to the number.
Your task is to reach the number with minimum as many number of
operations as possible.
Input : N = 8
Output : 4 Operations are required (two times operation 1 + two
times operation 0)
Start with 0 (always):
Operation 1: 0 + 1 = 1
Operation 1: 1 + 1 = 2
Operation 0: 2 * 2 = 4
Operation 0: 4 * 2 = 8
thank you.
Given a number N the task is to find an optimal solution to reach N
using two operations only. First option is operation 0: Double the
number and second option is operation is 1: Add one to the number.
Your task is to reach the number with minimum as many number of
operations as possible.
Input : N = 8
Output : 4 Operations are required (two times operation 1 + two
times operation 0)
Start with 0 (always):
Operation 1: 0 + 1 = 1
Operation 1: 1 + 1 = 2
Operation 0: 2 * 2 = 4
Operation 0: 4 * 2 = 8
thank you.