问题:
游戏规则:
两个人轮流掷骰子6次,并将每次投掷得点数累加起来,点数多者获胜。
要求求出玩家玩100局之后谁是最终的获胜者。
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int d1, d2, c1, c2, i, j;
c1 = c2 = 0;
//randomize();
for(i=1; i<=100; i++)
{
d1 = d2 = 0;
for(j=1; j<=6; j++)
{
d1 = d1 + rand()%6+1;
d2 = d2 + rand()%6+1;
}
if(d1>d2)
c1++;
else
if(d1,d2)
c2++;
}
if(c1>c2)
printf("\nThe first win.");
else
if(c1<c2)
printf("\nThe second win.");
else
printf("They tie");
return 0;
}
原文地址:http://blog.csdn.net/orangeisnotapple/article/details/44859087