C语言抛硬币基本程序,不要高级语言,需要rand srand 的就行,

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/05 15:49:46

C语言抛硬币基本程序,不要高级语言,需要rand srand 的就行,
C语言抛硬币
基本程序,不要高级语言,需要rand srand 的就行,

C语言抛硬币基本程序,不要高级语言,需要rand srand 的就行,
测试结果:
正面
下面
正面
正面
下面
正面
正面
下面
正面
下面
正面
正面
正面
总次数:13
正确的代码:
#include "stdio.h"
#include "conio.h"
#include
#include
#include
main()
{
int d,s,n,lastd=0,lasts=0,count=0;

time_t t;
\x09srand((unsigned)time(&t));
while(1)
{
count++;
if(rand()%2==0)
{
s++;
lastd=count;
printf("正面\n");

}
else
{
d++;
lasts=count;
printf("下面\n");

}
if(abs(lastd-lasts)>=3)
break;
}
printf("总次数:%d\n",count);
getch();
}
楼主好运!