扔骰子比大小
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
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(d1<d2)
c2++;
}
if(c1>c2)
printf("\nThe first win.\n");
else
if (c1<c2)
printf("\nThe second win.\n");
else
printf(“They tie.\n”);
return 0;
}
我查了查关于<time. h>相关内容,发现有些模棱两可,还是自己看看书,一般的书上都会有,我们用的最常见的就是用于生成随机数的功能。