编一个C语言程序 。用最普通的Turbo c++3.0 软件。

2025-05-22 16:19:49
推荐回答(2个)
回答(1):

1楼的回答有点问题,
j = rand() % 1999 + 1;
其中rand() % 1999只能生成0-1998之间的1999个数字,
所以这个表达式的值只能介于1-1999之间,2000出现率为0。
所以应该改为
j = rand() % 2000 + 1;

回答(2):

#include
#include
#include
int main()
{
int i,j;
srand(time(0));
for(i=0;i<3;i++) {
j = rand() % 1999 + 1;
printf("%d ", j);
}
return 0;
}