c语言 产生一个1~50的随机数
答案:5 悬赏:10
解决时间 2021-02-14 07:27
- 提问者网友:梧桐不渝
- 2021-02-13 14:05
c语言 产生一个1~50的随机数
最佳答案
- 二级知识专家网友:为你轻狂半世殇
- 2021-02-13 15:42
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void main()
{
int i,temp,tag=1;
srand((unsigned)time(NULL));
while(tag==1)
{
temp=rand();
if(temp>0&&temp<51)
{
i=temp;
printf("i为%d。\n是否退出?1.是;2.否。请选择:",i);
scanf("%d",&temp);
if(temp==1)
tag=0;
}
}
}
#include<stdlib.h>
#include<time.h>
void main()
{
int i,temp,tag=1;
srand((unsigned)time(NULL));
while(tag==1)
{
temp=rand();
if(temp>0&&temp<51)
{
i=temp;
printf("i为%d。\n是否退出?1.是;2.否。请选择:",i);
scanf("%d",&temp);
if(temp==1)
tag=0;
}
}
}
全部回答
- 1楼网友:哭不代表软弱
- 2021-02-13 18:26
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int i;
srand(time(NULL));
i = rand()%50+1;
return 0;
}
- 2楼网友:厭世為王
- 2021-02-13 17:31
#include <time.h>
#include <stdlib.h>
srand(time(NULL));
int i = rand() % 50 + 1;
这样就好了。
- 3楼网友:摧毁过往
- 2021-02-13 16:39
#include
#include
#include
int main(void)
{
int r;
srand(time(null));
r=rand()%6+1;
printf("%d",r);
return 0;
}
- 4楼网友:风格单纯
- 2021-02-13 16:25
楼上不能保证不同
两个循环了一个自减
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯