Probability of getting all possible values on throwing N dices | C # program to calculate the probability of all the possible values that can be obtained throwing N dices ; Store the probabilities ; Precompute the probabilities for values possible using 1 dice ; Compute the probabilies for all values from 2 to N ; Print the result ; Driver Code
using System ; class GFG { static void dicesSum ( int n ) { double [ , ] dp = new double [ n + 1 , 6 * n + 1 ] ; for ( int i = 1 ; i <= 6 ; i ++ ) dp [ 1 , i ] = 1 / 6.0 ; for ( int i = 2 ; i <= n ; i ++ ) for ( int j = i - 1 ; j <= 6 * ( i - 1 ) ; j ++ ) for ( int k = 1 ; k <= 6 ; k ++ ) { dp [ i , j + k ] += ( dp [ i - 1 , j ] * dp [ 1 , k ] ) ; } for ( int i = n ; i <= 6 * n ; i ++ ) { Console . WriteLine ( i + " ▁ " + Math . Round ( dp [ n , i ] * 1000.0 ) / 1000.0 ) ; } } static void Main ( ) { int n = 2 ; dicesSum ( n ) ; } }