C语言 编一个程序,产生0-100随机数,然后用选择排序法,从小到大排列

如题所述

第1个回答  2016-04-18
//#include "stdafx.h"//vc++6.0加上这一行.
#include "stdio.h"
#include "time.h"
#include "stdlib.h"
int main(void){
int nDec[100],i,j,k;
srand((unsigned)time(NULL));
for(i=0;i<100;nDec[i++]=rand());
for(i=0;i<100;i++){
for(k=i,j=k+1;j<100;j++)
if(nDec[k]>nDec[j]) k=j;
if(i!=k){
j=nDec[i];
nDec[i]=nDec[k];
nDec[k]=j;
}
printf("%d ",nDec[i]);
}
printf("\n");
return 0;
}本回答被提问者和网友采纳
第2个回答  2016-04-18
//#include "stdafx.h"//<a href="https://www.baidu.com/s?wd=vc%2B%2B6.0&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1dBnWDsrHnvnvDdnjR1nHR10ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnHb3rHR1rjc1nWbknWmsnHfvPs" target="_blank" class="baidu-highlight">vc++6.0</a>加上这一行.
#include "stdio.h"
#include "time.h"
#include "stdlib.h"
int main(void){
int nDec[100],i,j,k;
srand((unsigned)time(<a href="https://www.baidu.com/s?wd=NULL&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1dBnWDsrHnvnvDdnjR1nHR10ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnHb3rHR1rjc1nWbknWmsnHfvPs" target="_blank" class="baidu-highlight">NULL</a>));
for(i=0;i<100;nDec[i++]=rand());
for(i=0;i<100;i++){
for(k=i,j=k+1;j<100;j++)
if(nDec[k]<nDec[j]) k=j;
if(i!=k){
j=nDec[i];
nDec[i]=nDec[k];
nDec[k]=j;
}
printf("%d ",nDec[i]);
}
printf("\n");
return 0;
}
相似回答