#include <stdio.h>
#include <stdlib.h>
struct student
{
int score;
char*name;
};
int main()
{
struct student st1[5];
int i;
struct student maxstu;
struct student minstu;
for(i=0;i<sizeof(st1)/sizeof(st1[0]);i++){
printf("请输入第%d学生的名字\n",i+1);
st1[i].name=(char*)malloc(128);
scanf("%s",st1[i].name);
printf("请输入第%d个学生的成绩\n",i+1);
scanf("%d",&st1[i].score);
}
for(i=0;i<sizeof(st1)/sizeof(st1[0]);i++){
printf("%s的成绩是%d\n",st1[i].name,st1[i].score);
}
maxstu=minstu=st1[0];
for(i=0;i<5;i++){
if(maxstu.score<st1[i].score){
maxstu=st1[i];
}
if(minstu.score>st1[i].score){
minstu=st1[i];
}
}
printf("最高分是%s 成绩为%d\n",maxstu.name,maxstu.score);
printf("最低分是%s 成绩为%d\n",minstu.name,minstu.score);
return 0;
}
利用结构体求最高分最低分的分别是谁
最新推荐文章于 2022-06-22 15:28:01 发布