Check whether sum of digits at odd places of a number is divisible by K | javascript implementation of the above approach ; Converting integer to string ; Traversing the string ; Driver code
function sumDivisible ( n , k ) { var sum = 0 var num = n . toString ( ) for ( var i = 0 ; i < num . length ; i ++ ) { if ( i % 2 != 0 ) { sum = sum + Number ( num [ i ] ) } } if ( sum % k == 0 ) { return true ; } else { return false ; } } var n = 592452 var k = 3 if ( sumDivisible ( n , k ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }