fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. #define ROLLS 10000
  6.  
  7. int main(void) {
  8. int frequency[13] = {0};
  9. int die1, die2, sum;
  10.  
  11. srand(time(NULL));
  12.  
  13. for (int i = 0; i < ROLLS; i++) {
  14. die1 = rand() % 6 + 1;
  15. die2 = rand() % 6 + 1;
  16. sum = die1 + die2;
  17. frequency[sum]++;
  18. }
  19.  
  20. // 結果を表示
  21. printf("出た目の和の頻度:\n");
  22. for (int i = 2; i <= 12; i++) {
  23. printf("%d: %d\n", i, frequency[i]);
  24. }
  25.  
  26. return 0;
  27. }
Success #stdin #stdout 0s 5272KB
stdin
Standard input is empty
stdout
出た目の和の頻度:
2: 312
3: 564
4: 835
5: 1109
6: 1439
7: 1589
8: 1385
9: 1146
10: 788
11: 555
12: 278