雅安市委书记徐孟加#include <stdio.h> #include <stdlib.h>
/*C语⾔程序设计案例教程(廖湖声) P122 第四章上机练习第⼀题*/ /*北⼯⼤896 计算机*/
/*选择排序*/
int select(int num[],int count[]){
int i,j,max,temp_num,temp_count;
for(i=0;i<99;i++){
max=i;
for(j=i+1;j<100;j++){
if(count[j]>count[max]){
max=j;
}
}
if(max!=i){
/*交换num*/
temp_num=num[i];
num[i]=num[max];
num[max]=temp_num;
/*交换count*/微调
temp_count=count[i];
count[i]=count[max];
count[max]=temp_count;
新宽联
}
}
}
int main()
{
int num[100];
int i;
/*⽣成待排序列*/
for(i=0;i<100;i++){
num[i]=i+1;
count[i]=rand()%100;
}
select(num,count);//选择排序函数
/*打印结果*/
printf("Top 10(order by download times):\n");
for(i=0;i<10;i++){北工大
printf("number:%d,download times:%d\n",num[i],count[i]);
}
printf("\n");
printf("Never been download:\n");
for(i=0;i<100;i++){
if(count[i]==0)
printf("number:%d,download times:%d\n",num[i],count[i]);
刘智仁}
return0;
}