水平有限,如有不足请指出谢谢
个人思路及代码(C语言)
题目要求输出成绩最高学生和最低学生的姓名及学号,字符串中间有一空格。
思路:
1.结构体学生信息
2.只保存成绩最高的学生信息和成绩最低的学生信息。
3.注意输入输出格式%s,是否有&,%s输入输出不需要&。
学生结构体定义:
typedef struct
{
char name[12]; //姓名
char num[12]; //学号
int scores; //成绩
}stu;
代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct
{
char name[12];
char num[12];
int scores;
}stu;
void print(stu* a) {
printf("%s %s\n", a->name, a->num);
}
int main() {
stu max = { "","",0 };
stu min = { "","",100 };
stu box;
int a = 0;
scanf("%d", &a);
for (int i = 0;i < a;i++) {
scanf("%s", box.name);
scanf("%s", box.num);
scanf("%d", &box.scores);
if (box.scores > max.scores)
max = box;
if (box.scores < min.scores )
min = box;
}
print(&max);
print(&min);
return 0;
}