回顾:结构体:是一些值的集合,这些值叫做成员变量,可以是不同类型
输入两个学生学号,姓名和成绩(整数),分别存入结构体中,输出成绩较高的学生的学号,姓名和成绩。
知识点:结构体变量访问成员 ,是通过点操作符(.)访问的。点操作符接受两个操作数
分析思路:先定义所需信息,学号(num),姓名(name),成绩(score)放在结构体information中,将学生1,2的信息输入,要输出成绩较高学生的信息,只需要运用选择语句,用if比较成绩后输出即可。
代码实现
#include<stdio.h>
int main()
{
struct information
{
char num[20];
char name[20];
int score;
}student1, student2;
scanf("%s%s%d", student1.num, student1.name, &student1.score);
scanf("%s%s%d", student2.num, student2.name, &student2.score);
if (student1.score > student2.score)
{
printf("%s %s %d\n", student1.num, student1.name, student1.score);
}
else
{
printf("%s %s %d\n", student2.num, student2.name, student2.score);
}
return 0;
}