Number of non | return number of non negative integral solutions ; initialize total = 0 ; Base Case if n = 1 and val >= 0 then it should return 1 ; iterate the loop till equal the val ; total solution of equations and again call the recursive function Solutions ( variable , value ) ; return the total no possible solution ; driver code
def countSolutions ( n , val ) : NEW_LINE INDENT total = 0 NEW_LINE if n == 1 and val >= 0 : NEW_LINE INDENT return 1 NEW_LINE DEDENT for i in range ( val + 1 ) : NEW_LINE INDENT total += countSolutions ( n - 1 , val - i ) NEW_LINE DEDENT return total NEW_LINE DEDENT n = 5 NEW_LINE val = 20 NEW_LINE print ( countSolutions ( n , val ) ) NEW_LINE