#include <stdio.h>
int SUM(int score[],int sum)
{
int i;
for(i=0;i<=9;i++)
{
sum = sum+score[i];
}
return sum;
}
int PINGJUNSHU(int sum)
{
int pingjun;
pingjun = sum/10;
printf("平均分为:%d\n",pingjun);
return 0;
}
int MAX(int score[])
{
int i;
int max = score[0];
for(i=1;i<9;i++){
if(max<score[i]){
max = score[i];
}
}
printf("最高分为:%d\n",max);
return 0;
}
int MIN(int score[]){
int i ;
int min = score[0];
for(i=1;i<=9;i++){
if(min>score[i]){
min = score[i];
}
}
printf("最低分为:%d\n",min);
return 0;
}
int GOUDIPAIXU(int score[]){
int i,j;
for(i=0;i<=9;i++){
for(j=0;j<i;j++){
if(score[j]<score[j+1]){
int k;
k = score[j+1];
score[j+1] = score[j];
score[j] = k;
}
}
}
printf("****************\n");
printf("成绩从高到低排序为:\n");
int k;
for(k=0;k<=9;k++){
printf("%d\t",score[k]);
}
return 0;
}
int main()
{
int score[]={67,98,75,63,82,79,81,91,66,84};
int sum = 0;
sum = SUM(score,sum);
printf("总分为:%d\n",sum);
PINGJUNSHU(sum);
MAX(score);
MIN(score);
GOUDIPAIXU(score);
return 0;
}
运行成功
总分为:786
平均分为:78
最高分为:98
最低分为:63
****************
成绩从高到低排序为:
98 82 81 79 91 75 67 66 84 63
#include <stdio.h> int main() { int score[]={67,98,75,63,82,79,81,91,66,84}; int i,j; for(i=9;i>=0;i--) { for(j=0;j<i;j++) { if(score[j]<score[j+1]) { int k; k = score[j+1]; score[j+1] = score[j]; score[j] = k; } } } for(i=0;i<=9;i++) { printf("%d,",score[i]); } return 0; }
我理解的排序的本质是要把最大或者最小的数先·放在最后,然后就不管它,继续把第二大或者小的数按照相同的方法排序进行一定次数后自然就能完成排序(菜鸟,说的不太严谨)