#include <stdio.h>
#include <stdlib.h>
int roll_dice(void) {
return (rand() % 6) + 1; // returns a value between 1 and 6 }
int main(void) {
int sum, i;
int frequency[13] = {0}; // Array to store the frequency of sums (2-12)
// Simulate rolling two dice 100,000 times
for (i = 0; i < 100000; i++) {
int die1 = roll_dice();
int die2 = roll_dice();
sum = die1 + die2;
frequency[sum]++;
}
// Output the results
for (i = 2; i <= 12; i++) {
printf("%d\t%d\n", i
, frequency
[i
]); }
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCmludCByb2xsX2RpY2Uodm9pZCkgewogICAgcmV0dXJuIChyYW5kKCkgJSA2KSArIDE7ICAvLyByZXR1cm5zIGEgdmFsdWUgYmV0d2VlbiAxIGFuZCA2Cn0KCmludCBtYWluKHZvaWQpIHsKICAgIGludCBzdW0sIGk7CiAgICBpbnQgZnJlcXVlbmN5WzEzXSA9IHswfTsgIC8vIEFycmF5IHRvIHN0b3JlIHRoZSBmcmVxdWVuY3kgb2Ygc3VtcyAoMi0xMikKCiAgICAvLyBTaW11bGF0ZSByb2xsaW5nIHR3byBkaWNlIDEwMCwwMDAgdGltZXMKICAgIGZvciAoaSA9IDA7IGkgPCAxMDAwMDA7IGkrKykgewogICAgICAgIGludCBkaWUxID0gcm9sbF9kaWNlKCk7CiAgICAgICAgaW50IGRpZTIgPSByb2xsX2RpY2UoKTsKICAgICAgICBzdW0gPSBkaWUxICsgZGllMjsKICAgICAgICBmcmVxdWVuY3lbc3VtXSsrOwogICAgfQoKICAgIC8vIE91dHB1dCB0aGUgcmVzdWx0cwogICAgcHJpbnRmKCJTdW1cdEZyZXF1ZW5jeVxuIik7CiAgICBmb3IgKGkgPSAyOyBpIDw9IDEyOyBpKyspIHsKICAgICAgICBwcmludGYoIiVkXHQlZFxuIiwgaSwgZnJlcXVlbmN5W2ldKTsKICAgIH0KCiAgICByZXR1cm4gMDsKfQo=