程序代码:
#include<stdio.h> int main() { int i=0,j=0,n=5; float buf; float score[5][6]={0.0}; int a[5]={0}; printf("请录入五个学生5门课程成绩\n"); for(i=0;i<n;i++) { printf("请输入第%d个学生成绩:",i+1); scanf("%f %f %f %f %f",&score[i][0],&score[i][1],&score[i][2],&score[i][3],&score[i][4]); //输入数据 score[i][5]=score[i][0]+score[i][1]+score[i][2]+score[i][3]+score[i][4]; //计算总成绩 a[i]=i; } for(i=0;i<n;i++) { printf("第%d个学生:",i+1); printf("%.1f %.1f %.1f %.1f %.1f\t%.1f\n", score[i][0],score[i][1],score[i][2],score[i][3],score[i][4],score[i][5]); //输出成绩 } for(j=0;j<n-1;j++) { if (score[j][5]>score[j+1][5]) { buf=score[j][5]; score[j][5]=score[j+1][5]; score[j+1][5]=buf; buf=a[j]; a[j]=a[j+1]; a[j+1]=buf; } } printf("总分最高的是第%d个学生(总分:%f)",a[n-1]+1,score[n-1][5]); //输出最高分 return 0; }