#include
float search(float a[3][4])
{
int i,j;
float max=0;
float total[3]={0};
printf("每个学生的总分为:\n");
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
total[i]+=a[i][j];
}
printf("%.2f ",total[i]);//每个学生的总成绩
}
for(i=0;i<3;i++)
{
if(max
max=total[i];
}
printf("\n最高分的学生的总成绩为\n%.2f",max);
printf("\n最高分学生的数据为:");
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
if(total[i]==max)
printf("%.2f ",a[i][j]);
}
}
return 0;
}
int main()
{
int i,j;
printf("请输入学生的成绩:\n");
float a[3][4]={0};
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
scanf("%f",&a[i][j]);
}
}
printf("最高分学生的数据\n");
search(a);
return 0;
}
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
if(total[i]==max)
printf("%.2f ",a[i][j]);
}
}
这块代码的我理解的是当某个学生的成绩为最高分时,输出其各个成绩吗,这样对吗?
if(total[i]==max)
printf("%.2f ",a[i][j]);
这里有点不理解
就是这样,当某个学生的成绩为最高分时,输出他的4门成绩