Output the highest score, the highest score student's student number, and the highest score student's name.
#include<stdio.h>
#include<stdlib.h>
struct student
{
int num;
char name[20];
float score;
};
int main(void )
{
int i,m;
float maxscore;
struct student stu[5]=
{
{
001,"小黄",110},
{
002,"小张",105},
{
003,"小李",102},
{
004,"小周",108},
{
005,"小美",100}
};
m=0;
maxscore=stu[0].score;
for(i=1;i<5;i++)
{
if(stu[i].score>maxscore)
{
maxscore=stu[i].score; //记录最高成绩
m=i; //记录最高成绩下标
}
}
for(i=0;i<5;i++)
{
printf("学号:%d 姓名:%s 成绩:%5.1f \n",stu[i].num,stu[i].name,stu[i].score);//将所有学生的信息显示出来
}
printf("最高分是:%5.1f\n",maxscore); //输出最高成绩
printf("最高分学生的学号:%d\n",stu[m].num); //输出最高成绩的学号
printf("最高分学生的姓名:%s\n",stu[m].name); //输出最高成绩的下标
return 0;
}
I have only recently come into contact with the c language error, please correct me.
Leave your footsteps below.
(﹡ˆOˆ﹡)