Minimize the sum of digits of A and B such that A + B = N | Function to return the minimum possible sum of digits of A and B such that A + B = n ; Find the sum of digits of n ; If num is a power of 10 ; Driver code
function minSum ( n ) { var sum = 0 ; while ( n > 0 ) { sum += ( n % 10 ) ; n = parseInt ( n / 10 ) ; } if ( sum == 1 ) return 10 ; return sum ; } var n = 1884 ; document . write ( minSum ( n ) ) ;