text: Count ways to obtain given sum by repeated throws of a dice | C ++ program for the above approach ; 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: #include <bits/stdc++.h> NEW_LINE using namespace std ; int findWays ( int N ) { if ( N == 0 ) { return 1 ; } int cnt = 0 ; for ( int i = 1 ; i <= 6 ; i ++ ) { if ( N - i >= 0 ) { cnt = cnt + findWays ( N - i ) ; } } return cnt ; } int main ( ) { int N = 4 ; cout << findWays ( N ) ; return 0 ; }