C语言 编一个程序,产生0-100随机数,然后用选择排序法,从小到大排列
2个回答
2016-04-18 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
//#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;
}
#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;
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
//#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;
}
#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;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询