Minimum number of operations required to reduce N to 0 | C ++ Program to implement the above approach ; Function to find the minimum steps required to reduce n ; Base case ; Return answer based on parity of n ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int downToZero ( int n ) { if ( n <= 3 ) return n ; return n % 2 == 0 ? 3 : 4 ; } int main ( ) { int n = 4 ; cout << downToZero ( n ) ; return 0 ; }