模拟 N 骰子滚轮的 C++ 程序
这是模拟N骰子滚轮的代码。这可以通过生成1-6之间的随机数来完成。
算法
Begin Declare n Read n For i = 0 to n-1 do Generate sequence with rand() mod 6 + 1 Print the sequence Done End
示例代码
#include输出结果using namespace std; int main(int argc, char **argv) { cout << "输入骰子数: "; int n; cin >> n; cout << "骰子上的值是: "; for (int i = 0; i < n; i++) cout << (rand() % 6) + 1<<" "; }
输入骰子数: 骰子上的值是: 2 5 4 2 6 2 5