#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define SIDES 6 // サイコロの面の数
int saikoro(void) {
return (rand() % SIDES
) + 1; // 1から6の間の数を返す }
int main(void) {
int i, roll1, roll2;
int histogram[2 * SIDES + 1]; // 和は2から12までの範囲
// ヒストグラムの初期化
for (i = 0; i <= 2 * SIDES; i++) {
histogram[i] = 0;
}
// 乱数生成器のシードを設定
// サイコロを10万回振る
for (i = 0; i < 100000; i++) {
roll1 = saikoro(); // 1つ目のサイコロ
roll2 = saikoro(); // 2つ目のサイコロ
int sum = roll1 + roll2; // 和を計算
histogram[sum]++; // 和の出現回数をカウント
}
// 結果を表示
for (i = 2; i <= 12; i++) {
printf("%d\t%d\n", i
, histogram
[i
]); }
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHRpbWUuaD4KCiNkZWZpbmUgU0lERVMgNiAgLy8g44K144Kk44Kz44Ot44Gu6Z2i44Gu5pWwCgppbnQgc2Fpa29ybyh2b2lkKSB7CiAgICByZXR1cm4gKHJhbmQoKSAlIFNJREVTKSArIDE7ICAvLyAx44GL44KJNuOBrumWk+OBruaVsOOCkui/lOOBmQp9CgppbnQgbWFpbih2b2lkKSB7CiAgICBpbnQgaSwgcm9sbDEsIHJvbGwyOwogICAgaW50IGhpc3RvZ3JhbVsyICogU0lERVMgKyAxXTsgIC8vIOWSjOOBrzLjgYvjgokxMuOBvuOBp+OBruevhOWbsgoKICAgIC8vIOODkuOCueODiOOCsOODqeODoOOBruWIneacn+WMlgogICAgZm9yIChpID0gMDsgaSA8PSAyICogU0lERVM7IGkrKykgewogICAgICAgIGhpc3RvZ3JhbVtpXSA9IDA7CiAgICB9CgogICAgLy8g5Lmx5pWw55Sf5oiQ5Zmo44Gu44K344O844OJ44KS6Kit5a6aCiAgICBzcmFuZCh0aW1lKE5VTEwpKTsKCiAgICAvLyDjgrXjgqTjgrPjg63jgpIxMOS4h+WbnuaMr+OCiwogICAgZm9yIChpID0gMDsgaSA8IDEwMDAwMDsgaSsrKSB7CiAgICAgICAgcm9sbDEgPSBzYWlrb3JvKCk7ICAvLyAx44Gk55uu44Gu44K144Kk44Kz44OtCiAgICAgICAgcm9sbDIgPSBzYWlrb3JvKCk7ICAvLyAy44Gk55uu44Gu44K144Kk44Kz44OtCiAgICAgICAgaW50IHN1bSA9IHJvbGwxICsgcm9sbDI7ICAvLyDlkozjgpLoqIjnrpcKICAgICAgICBoaXN0b2dyYW1bc3VtXSsrOyAgLy8g5ZKM44Gu5Ye654++5Zue5pWw44KS44Kr44Km44Oz44OICiAgICB9CgogICAgLy8g57WQ5p6c44KS6KGo56S6CiAgICBwcmludGYoIuWSjFx06aC75bqmXG4iKTsKICAgIGZvciAoaSA9IDI7IGkgPD0gMTI7IGkrKykgewogICAgICAgIHByaW50ZigiJWRcdCVkXG4iLCBpLCBoaXN0b2dyYW1baV0pOwogICAgfQoKICAgIHJldHVybiAwOwp9Cg==