Number of N digit integers with weight W | Function to find total possible numbers with n digits and weight w ; When Weight of an integer is Positive ; Subtract the weight from 9 ; When weight of an integer is negative ; add the weight to 10 to make it positive ; Driver code ; number of digits in an integer and w as weight ; print the total possible numbers with n digits and weight w
function findNumbers ( n , w ) { let x = 0 , sum = 0 ; if ( w >= 0 && w <= 8 ) { x = 9 - w ; } else if ( w >= - 9 && w <= - 1 ) { x = 10 + w ; } sum = Math . pow ( 10 , n - 2 ) ; sum = ( x * sum ) ; return sum ; } let n , w ; n = 3 ; w = 4 ; document . write ( findNumbers ( n , w ) ) ;