Number of solutions for the equation x + y + z <= n | Function to find the number of solutions for the equation x + y + z <= n , such that 0 <= x <= X , 0 <= y <= Y , 0 <= z <= Z . ; To store answer ; for values of x ; for values of y ; Maximum possible value of z ; If z value greater than equals to 0 then only it is valid ; Find minimum of temp and z ; Return required answer ; Driver Code
function NumberOfSolutions ( x , y , z , n ) { var ans = 0 ; for ( var i = 0 ; i <= x ; i ++ ) { for ( var j = 0 ; j <= y ; j ++ ) { var temp = n - i - j ; if ( temp >= 0 ) { temp = Math . min ( temp , z ) ; ans += temp + 1 ; } } } return ans ; } var x = 1 , y = 2 , z = 3 , n = 4 ; document . write ( NumberOfSolutions ( x , y , z , n ) ) ;