用C语言,如何随机生成10个三位数。。。。。。

Jiang_hy 2002-05-17 12:23:02
如题 :)
...全文
1329 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
a19838848 2002-05-19
  • 打赏
  • 举报
回复
agree 楼上
林水福 2002-05-18
  • 打赏
  • 举报
回复
哦,a=100+rand()%900;
林水福 2002-05-18
  • 打赏
  • 举报
回复
a=100+rand()%1000
taockey 2002-05-17
  • 打赏
  • 举报
回复
randomize();
for(i=0;i<=3;)
{
j=random(1000);
if(j>100)
{
printf("%d",j);
i++;
}
}

头文件就不用说了吧
xiaoxiangyy 2002-05-17
  • 打赏
  • 举报
回复
呛!那有那么复杂
..
#include <cstdlib>
#include <ctime>
..
stand( time( 0 ) );
int i = 0;
while( ++i <= 3 )
cout << 100 + rand() % 999;
...
coldcrane 2002-05-17
  • 打赏
  • 举报
回复
num=random(900)+100;
operaphantom 2002-05-17
  • 打赏
  • 举报
回复

#include <stdlib.h>
#include <stdio.h>
#include <time.h>

void main( void )
{
int i;
int count = 0;

/* Seed the random-number generator with current time so that
* the numbers will be different every time we run.
*/
srand( (unsigned)time( NULL ) );

/* Display 10 numbers. */
while(count < 10)
{
i = rand();
if((100 <= i)&&(i <= 999))
{
printf( "%d\t%6d\n", count,i);
count++;
}

}
}
spark_li 2002-05-17
  • 打赏
  • 举报
回复
int array[10]

srand((unsigned int)time(NULL));

for(int i = 0;i<10;i++)
array[i]=rand(100);
prototype 2002-05-17
  • 打赏
  • 举报
回复
it is 'rand' in the standard header '<stdlib.h>'.

do it like this:

srand(0);

for (int i = 0; i < 10; ++i)
rand_num[i] = (int)(900.0 * rand()/(float)RAND_MAX) + 100;
opengl3d 2002-05-17
  • 打赏
  • 举报
回复
100+(0--900)
类似的差不多
ccnuxjg 2002-05-17
  • 打赏
  • 举报
回复
rand()
判断是否是三位数
Jiang_hy 2002-05-17
  • 打赏
  • 举报
回复
。。。

是Random()函数吧?

int random(int num)

返回0到num-1 之间的整数

我想要的是3位整数:)
ckc 2002-05-17
  • 打赏
  • 举报
回复
c有rand函数啊
可以直接生成随机数
注意使用之前最好先初始化种子
Jiang_hy 2002-05-17
  • 打赏
  • 举报
回复


楼上的,我今天下午有事情,半天没来,你们就...

想分想疯了:) 开个玩笑,向你们致以十二分的感谢!!!
fengzheng 2002-05-17
  • 打赏
  • 举报
回复
我又没有市场了
尽力吧!
#include<stdlib.h>
#include<time.h>
.
srand(time(0))
int ch;
ch=100+rand()% 999
swingerleung 2002-05-17
  • 打赏
  • 举报
回复
//VC6.0下编译通过的版本
#include "stdlib.h"
#include "stdio.h"
#include <time.h>

void main()
{
int i;
int num[10];
srand( (unsigned)time( NULL ) );

for(i=0; i<10; i++)
{
num[i] = rand()%899+100;
printf("%d\n",num[i]);
}
}
cloud_leonhart 2002-05-17
  • 打赏
  • 举报
回复
#include "stdlib.h"
#include "stdio.h"
void main()
{
int i;
int num[10];
randomize();
for(i=0; i<10; i++)
{
num[i] = random(899)+100
}
getch();
}

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧