编写一个C++程序,模拟掷10000次骰子,计算每一个点数出现的概率.

求详细编程!!!!

#include <iostream>
#include <ctime>
using namespace std;

int main() {
int counts[6] = { 0 };
const int times = 10000;
srand(time(NULL));
for (int i = 0; i < times; i++) {
counts[rand() % 6]++;
}
for (int i = 0; i < 6; i++) {
cout << "掷出 " << i + 1 << " 的概率为 " << 100.0 * counts[i] / times << " %" << endl;
}
}

追问

可以运行吗??

温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-03-05
1/6.....................
相似回答