fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int saikoro(void) {
  5. return (rand() % 6) + 1;
  6. }
  7.  
  8. int main(void) {
  9. int sum, i;
  10. int frequency[13] = {0};
  11.  
  12. for (i = 0; i < 100000; i++) {
  13. int die1 = saikoro();
  14. int die2 = saikoro();
  15. sum = die1 + die2;
  16. frequency[sum]++;
  17. }
  18.  
  19. printf("和,頻度\n");
  20. for (i = 2; i <= 12; i++) {
  21. printf("%d,%d\n", i, frequency[i]);
  22. }
  23.  
  24. return 0;
  25. }
  26.  
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
和,頻度
2,2760
3,5546
4,8388
5,11209
6,13914
7,16786
8,13672
9,11106
10,8439
11,5462
12,2718