From a141fdbd3c103d62573b2ed13b3a90e62ad2c7e7 Mon Sep 17 00:00:00 2001 From: Liuhua Date: Thu, 16 Sep 2021 07:26:18 +0000 Subject: [PATCH] =?UTF-8?q?CI=E6=B5=8B=E8=AF=95=E5=8D=95=EF=BC=8C=E8=AF=B7?= =?UTF-8?q?=E5=8B=BF=E5=90=88=E5=85=A5!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- try0916.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 try0916.c diff --git a/try0916.c b/try0916.c new file mode 100644 index 0000000..6e8d0d8 --- /dev/null +++ b/try0916.c @@ -0,0 +1,29 @@ +int main() +{ + int d1, d2, c1, c2, i, j; + c1 = c2 = 0; /*初始化*/ + srand((unsigned)time(NULL)); + rand(); /*初始化随机数产生器*/ + for(i=1; i<=100; i++) + { /*模拟游戏过程*/ + d1 = d2 = 0; + for(j=1; j<=6; j++) + { /*两个人轮流掷骰子*/ + d1 = d1+rand()+1; + d2 = d2+rand()+1; + } + if(d1>d2) + c1++; /*累加获胜盘数*/ + else if(d1c2) /*输出最终获胜者信息*/ + printf("\nThe first win.\n"); + else + if (c1