Smallest number required to be added to M to make it divisible by N | Function to find the smallest number greater than or equal to N , that is divisible by k ; Function to find the smallest number required to be added to to M to make it divisible by N ; Stores the smallest multiple of N , greater than or equal to M ; Return the result ; Given Input ; Function Call
function findNum ( N , K ) { var rem = ( N + K ) % K ; if ( rem == 0 ) return N ; else return N + K - rem ; } function findSmallest ( M , N ) { var x = findNum ( M , N ) ; return x - M ; } var M = 100 , N = 28 ; document . write ( findSmallest ( M , N ) ) ;