text: 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 ; number of digits in an integer and w as weight ; print the total possible numbers with n digits and weight w
code: < ? php function findNumbers ( $ n , $ w ) { $ x = 0 ; $ sum = 0 ; if ( $ w >= 0 && $ w <= 8 ) { $ x = 9 - $ w ; } else if ( $ w >= -9 && $ w <= -1 ) { $ x = 10 + $ w ; } $ sum = pow ( 10 , $ n - 2 ) ; $ sum = ( $ x * $ sum ) ; return $ sum ; } $ n = 3 ; $ w = 4 ; echo findNumbers ( $ n , $ w ) ;