输出成绩输出最大的
结构体:
struct Student
{
int num;
char name[50];
char gender[20];
float scores;
};//注意有;
注意代码如何引用:
struct Student n[2];
struct Student n2;
如何调用里面的域:
n[0].scores<n[1].scores
代码:
#include <stdio.h>
#include <string.h>
struct Student
{
int num;
char name[50];
char gender[20];
float scores;
};
int main()
{
struct Student n[2];
struct Student n2;
struct Student max;
;
for(int i = 0;i<2;i++){
printf("请输入第%d名学生的信息:\n",i+1);
puts("学号:1?2");
scanf("%d",&n[i].num);
puts("姓名:");
scanf("%s",&n[i].name);
puts("性别:男?女");
scanf("%s",&n[i].gender);
puts("成绩:");
scanf("%f",&n[i].scores);//double型用%lf,float用%f,不然报错
}
max = n[0];
if(n[0].scores<n[1].scores){
max =n[1];
}if(n[0].scores == n[1].scores){
puts("这俩一样优秀");
}
if(n[0].scores != n[1].scores){
printf("成绩较高的学生信息:学号:%d \n姓名:%s \n性别:%s \n成绩:%f \n",max.num,max.name,max.gender,max.scores);
}
return 0;
}
结果: