已知学生的信息包括姓名、成绩。编写程序从键盘输入5个学生的信息,输出其中成绩最高者的姓名和成绩。
输入格式:
每条信息占一行,姓名和成绩之间用空格分隔。
输出格式:
输出成绩保留1位小数。
输入样例:
aaaa 80
bbbb 95
cccc 74
dddd 65
eeee 86
输出样例:
name = bbbb, score = 95.0
代码如下:
#include<stdio.h>
#include<string.h>
struct student{
char name[7];
int age;
}stds[5];
int main()
{
int i,max;
for(i=0;i<5;i++)
{
scanf("%s %d\n",&stds[i].name,&stds[i].age);
}
max=0;
for(i=1;i<5;i++)
if(stds[i].age>stds[max].age)
max=i;
printf("name = %s, score = %.1f",stds[max].name,(double)stds[max].age);
}