我的程序

来源:百度知道 编辑:UC知道 时间:2024/06/07 02:18:12
为什么我的程序不能运行!rand 怎样让它在X到Y范围内产生随机数!
#include "stdio.h"
int four;
void main()
{
int one,b[100],three,derre;
printf("su lu ------>\n");
for(one=0;one<=99;one++)
{
b[one]= rand()%1000;
printf("%d ",b[one]);
if(one%10==0)printf("\n");
}
printf("kei c------->");
for(one=0;one<=99;one++)
{
three=0.;
for(four=0;four<=98;four++)
{
if(b[four]>b[four+1])
{derre=b[four];b[four]=b[four+1];b[four+1]=derre;}
three=1;
}
if(three=0&&four=98) break;
}
printf("chen gong ------>\n");
for(one=0;one<=99;one++)
{
printf("%d ",b[one]);
if(one%10==0) printf("\n");
}
}

原程序修改如下:
//---------------------------------------------------------------------------

#include "stdio.h"
#include <stdlib.h> /*用到了rand()函数*/
#include <time.h> /*用于初始化随机数生成器*/
int four;
void main()
{
int one,b[100],three,derre;
printf("su lu ------>\n");
srand(time(NULL)); /*初始化随机数生成器,srand()函数在stdlib.h中声明,time()函数在time.h中声明*/
for(one=0;one<=99;one++)
{
b[one]= rand()%1000;
printf("%d ",b[one]);
if(one%10==0)printf("\n");
}
printf("kei c------->");
for(one=0;one<=99;one++)
{
three=0.;
for(four=0;four<=98;four++)
{
if(b[four]>b[four+1])
{derre=b[four];b[four]=b[four+1];b[four+1]=derre;}
three=1;
}
if(three==0&&four==98) break;/*注意这里,应该用==而不是=*/
}
printf("chen gong ------>\n");
for(one=0;one<=99;one++)
{