C语言抛硬币基本程序,不要高级语言,需要rand srand 的就行,
来源:学生作业帮 编辑:搜狗做题网作业帮 分类:综合作业 时间:2024/07/08 11:26:33
C语言抛硬币
基本程序,不要高级语言,需要rand srand 的就行,
基本程序,不要高级语言,需要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();
}
楼主好运!
正面
下面
正面
正面
下面
正面
正面
下面
正面
下面
正面
正面
正面
总次数: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();
}
楼主好运!
C语言抛硬币基本程序,不要高级语言,需要rand srand 的就行,
C语言如何srand和rand函数产生10个1-100内的随机数
c语言程序的基本结构?
C语言srand((unsigned)time(NULL));
c语言,使用随机函数rand()编写一个猜数字的游戏程序
用c语言写两个程序,1,集合的交并差运算.2,计算关系的闭包(3种)不要求功能非常完备,能实现最基本的就行,采纳了把我所
在语言处理程序中,解释程序的功能是() A.解释执行高级语言程序 B.将汇编语言程序编译成目标程序 C.解释执行汇编语言
c语言中如何用srand产生0-1000000的随机数
C语言用rand产生的是伪随机数么
C语言rand()函数产生的最大随机数是多少?
一个关于C语言里rand()函数的问题
C语言rand产生 a-b之间的随机数~谢谢