You have given "k" dice. How many way you can get a sum "S" and yes you have to throw all the dice. Write program for this.
Its same permutations program...but we have to try with all the six S(1,2,3,4,5,6)
possibilities for a dice. Exit condition will be
If all the dice run out.
SumP(dice,sum) = SumP(dice-1,sum-i)+i (from S).
Its same permutations program...but we have to try with all the six S(1,2,3,4,5,6)
possibilities for a dice. Exit condition will be
If all the dice run out.
SumP(dice,sum) = SumP(dice-1,sum-i)+i (from S).
Adding program:
ReplyDelete#include
using namespace std;
#define SIZE 6
void print( int out[], int size)
{
int i;
for ( i = 0; i < size; i++)
cout<>dice;
cout<<"Give the expected Sum of dices:"<>sum;
int in[SIZE] = { 1,2, 3,4, 5,6};
int out[SIZE];
generate(in,out,0,SIZE,dice,sum);
return 0;
}