#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define SIDES 6 // サイコロの面の数
int saikoro(void) {
double a;
a
= (double)rand() / RAND_MAX
; return (int)(a * SIDES) + 1; // 1から6の間の数を返す
}
int main(void) {
int i, die_roll;
int histogram[SIDES + 1]; // サイド1-6のヒストグラム配列
// ヒストグラムの初期化
for (i = 0; i <= SIDES; i++) {
histogram[i] = 0;
}
// 乱数生成器のシードを設定
// サイコロを2回振る
for (i = 0; i < 2; i++) {
die_roll = saikoro();
histogram[die_roll]++;
}
// 結果を表示
for (i = 1; i <= SIDES; i++) {
printf("%d\t%d\n", i
, histogram
[i
]); }
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHRpbWUuaD4KCiNkZWZpbmUgU0lERVMgNiAgLy8g44K144Kk44Kz44Ot44Gu6Z2i44Gu5pWwCgppbnQgc2Fpa29ybyh2b2lkKSB7CiAgICBkb3VibGUgYTsKICAgIGEgPSAoZG91YmxlKXJhbmQoKSAvIFJBTkRfTUFYOwogICAgcmV0dXJuIChpbnQpKGEgKiBTSURFUykgKyAxOyAvLyAx44GL44KJNuOBrumWk+OBruaVsOOCkui/lOOBmQp9CgppbnQgbWFpbih2b2lkKSB7CiAgICBpbnQgaSwgZGllX3JvbGw7CiAgICBpbnQgaGlzdG9ncmFtW1NJREVTICsgMV07ICAvLyDjgrXjgqTjg4kxLTbjga7jg5Ljgrnjg4jjgrDjg6njg6DphY3liJcKCiAgICAvLyDjg5Ljgrnjg4jjgrDjg6njg6Djga7liJ3mnJ/ljJYKICAgIGZvciAoaSA9IDA7IGkgPD0gU0lERVM7IGkrKykgewogICAgICAgIGhpc3RvZ3JhbVtpXSA9IDA7CiAgICB9CgogICAgLy8g5Lmx5pWw55Sf5oiQ5Zmo44Gu44K344O844OJ44KS6Kit5a6aCiAgICBzcmFuZCh0aW1lKE5VTEwpKTsKCiAgICAvLyDjgrXjgqTjgrPjg63jg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