Minimum positive integer to divide a number such that the result is an odd | C ++ program to make a number odd ; Function to find the value ; Return 1 if already odd ; Check how many times it is divided by 2 ; Driver code
#include <iostream> NEW_LINE using namespace std ; int makeOdd ( int n ) { if ( n % 2 != 0 ) return 1 ; int resul = 1 ; while ( n % 2 == 0 ) { n /= 2 ; resul *= 2 ; } return resul ; } int main ( ) { int n = 36 ; cout << makeOdd ( n ) ; return 0 ; }