怎么产生一个随时间变化的随机数
答案:4 悬赏:10
解决时间 2021-01-24 02:44
- 提问者网友:两耳就是菩提
- 2021-01-23 02:21
怎么产生一个随时间变化的随机数
最佳答案
- 二级知识专家网友:神也偏爱
- 2021-01-23 03:46
#include"stdio.h"
#include"time.h"
#include"windows.h"
main()
{
int n=100,x,i;
srand((unsigned)time(NULL));
for(i=0;i<1000;i++)
{
x=rand()%100+1;
printf("x=%d\n",x);
Sleep(1000);
}
}
全部回答
- 1楼网友:深街酒徒
- 2021-01-23 06:12
这题挺简单,%为求余数
#include<stdio.h>
#include<time.h>
int main()
{
int x;
srand((unsignde)time(NULL));
x = rand() % 100; //产生0 -- 99 之间的随机数
if(x == 0)
{
x = 100; //将0转换为100
}
}
#include<stdio.h>
#include<time.h>
int main()
{
int x;
srand((unsignde)time(NULL));
x = rand() % 100; //产生0 -- 99 之间的随机数
if(x == 0)
{
x = 100; //将0转换为100
}
}
- 2楼网友:鸠书
- 2021-01-23 05:15
#include <stdlib.h>
#include <time.h>
srand( time(NULL) );
for( i = 0; i < 10; i++ )
printf( "Random number #%d: %d\n", i, rand()%100 );
//产生10个随即数..
#include <time.h>
srand( time(NULL) );
for( i = 0; i < 10; i++ )
printf( "Random number #%d: %d\n", i, rand()%100 );
//产生10个随即数..
- 3楼网友:底特律间谍
- 2021-01-23 05:05
#include <iostream>
#include<stdlib.h>
#include<time.h>
int main()
{
int i;
printf("Ten random numbers from 0 to 99\n\n");
for(i=0; i<10; i++)
printf("%d\n", rand() % 100+1);
return 0;
}
#include<stdlib.h>
#include<time.h>
int main()
{
int i;
printf("Ten random numbers from 0 to 99\n\n");
for(i=0; i<10; i++)
printf("%d\n", rand() % 100+1);
return 0;
}
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯