text: Count ways to obtain given sum by repeated throws of a dice | Function to find the number of ways to get the sum N with throw of dice ; Base Case ; Stores the count of total number of ways to get sum N ; Recur for all 6 states ; Return answer ; Driver Code ; Function call
code: function findWays ( N ) { if ( N == 0 ) { return 1 ; } var cnt = 0 ; for ( var i = 1 ; i <= 6 ; i ++ ) { if ( N - i >= 0 ) { cnt = cnt + findWays ( N - i ) ; } } return cnt ; } var N = 4 ; document . write ( findWays ( N ) ) ;