1个回答
展开全部
#include "stdio.h"
#include <stdlib.h>
#include "time.h"
void f(char *p){
char i,j,k;
for(i=0;i<9;i++){
for(k=i,j=k+1;j<10;j++)
if(p[k]>p[j])
k=j;
if(k!=i)
j=p[k],p[k]=p[i],p[i]=j;
}
}
int main(int argv,char *argc[]){
char v[10][10],i,j;
int t;
srand((unsigned)time(NULL));
printf("The original array is as follows:\n");
for(i=0;i<10;i++){
for(j=0;j<10;printf("%3d",v[i][j++]=rand()%90+10));
printf("\n");
f(v[i]);
}
printf("\nIn line after sorting and its average:\n");
for(i=0;i<10;i++){
for(t=j=0;j<10;printf("%3d",v[i][j++]))
t+=v[i][j];
printf(" %.2f\n",t/10.0);
}
printf("\n");
return 0;
}
运行样例:
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询