fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. #define SIDES 6
  6.  
  7. int saikoro(void) {
  8. return (rand() % SIDES) + 1;
  9. }
  10.  
  11. int main(void) {
  12. int i, roll1, roll2;
  13. int histogram[2 * SIDES + 1];
  14.  
  15. for (i = 0; i <= 2 * SIDES; i++) {
  16. histogram[i] = 0;
  17. }
  18.  
  19. srand(time(NULL));
  20.  
  21. for (i = 0; i < 100000; i++) {
  22. roll1 = saikoro();
  23. roll2 = saikoro();
  24. int sum = roll1 + roll2;
  25. histogram[sum]++;
  26. }
  27.  
  28. printf("和\t頻度\n");
  29. for (i = 2; i <= 12; i++) {
  30. printf("%d\t%d\n", i, histogram[i]);
  31. }
  32.  
  33. return 0;
  34. }
  35.  
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
和	頻度
2	2703
3	5535
4	8399
5	11257
6	13922
7	16758
8	13600
9	11128
10	8471
11	5516
12	2711