試著寫寫看 語法沒有很在意
void GetPossibilityOfThrowDice (int numberOfDice)
{
// We want to get resultArray from 1 to 6N
int *resultArray = new int[6*numberOfDice+1];
SubFunction (0, numberOfDice, resultArray);
for(int i=0; i<=numberOfDice*6; i++)
{
printf("%d with possibility %f\n", i, (float)resultArray[i]/6*numberOfDice);
}
}
void SubFunction (int subSum, int remainingDice, int* resultArray)
{
// End Condition
if (remainingDice == 1)
{
for (int i=1; i<=6; ++i)
{
resultArray[subSum+i] += 1;
}
}
for (int i=1; i<=6; ++i)
{
SubFunction (subSum+i, remainingDice-1, resultArray);
}
}