Greatest odd factor of an even number | Function to print greatest odd factor ; Initialize i with 1 ; Iterate till i <= pow_2 ; Find the pow ( 2 , i ) ; If factor is odd , then print the number and break ; Given Number ; Function Call
function greatestOddFactor ( n ) { let pow_2 = ( Math . log ( n ) ) ; let i = 1 ; while ( i <= pow_2 ) { let fac_2 = ( 2 * i ) ; if ( n % fac_2 == 0 ) { if ( ( n / fac_2 ) % 2 == 1 ) { return ( n / fac_2 ) ; } } i += 1 ; } return 0 ; } let N = 8642 ; document . write ( greatestOddFactor ( N ) ) ; ;