Sum of n digit numbers divisible by a given number | Returns sum of n digit numbers divisible by ' number ' ; compute the first and last term ; sum of number which having n digit and divisible by number ; Driver Code
function totalSumDivisibleByNum ( n , number ) { let firstnum = Math . pow ( 10 , n - 1 ) ; let lastnum = Math . pow ( 10 , n ) ; let sum = 0 ; for ( let i = firstnum ; i < lastnum ; i ++ ) if ( i % number == 0 ) sum += i ; return sum ; } let n = 3 , num = 7 ; document . write ( totalSumDivisibleByNum ( n , num ) ) ;