你会想帮助我解决以下问题吗? 感谢。
Question: The percentage of rolling 3 dices of face 6 in one go can be found out mathematically or simulation. The Monte Carlo method is a computer process to find out the solution of a problem by computer simulation. Write a program that roll three dices, calculate their sum, and find out the probability of rolling each possible outcome.
You are given a skeleton program q1dskeleton.c that generates the statistics of rolling a dice of six sides 10000 times. Modify the program so that it generates the statistics of the sum of rolling three six-sided dices. An example of the program output is given in the following. Note that because of the random nature of dice rolling.
Skeleton:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define SIZE 7
int main() {
int face, roll, frequency[SIZE] = { 0 };
srand( time(NULL) );
for (roll = 1; roll <= 10000; roll++) {
face = rand() % 6 + 1;
++frequency[face];
}
printf("%s%12s
", "Face", "Frequency");
for (face = 1; face <= SIZE - 1; face++)
printf("%4d%12d
", face, frequency[face]);
getchar();
}
产出:
Face Frequency
3 49
4 129
5 276
6 481
7 669
8 994
9 1131
10 1213
11 1269
12 1197
13 962
14 707
15 464
16 268
17 144
18 47