输入和学生成绩的输出

#include<stdio.h>

/*
	学生的结构的定义。
	成员变量名称、卷号、受试者的结果。
	两名学生从键盘读取信息。
	最后,良好的背景输出谁在公告栏中承认比分淘汰。
	假设同样的比分,在公告栏中一同显示出来。

*/ //定义一个结构体类型 struct Student { char name[20]; //名字 char idNum[20]; //学籍号 float score; }; void compare(struct Student stus[],int count); int main() { //定义结构体类型的结构体数组 struct Student stu[2]; for (int i = 0; i < 2; ++i) { printf("请输入第%d个学生的姓名:\n",i+1); //输入学生的姓名 scanf("%s",stu[i].name); printf("请输入第%d个学生的学籍号:\n",i+1); //输入学生的学籍号 scanf("%s",stu[i].idNum); printf("请输入第%d个学生的成绩:\n",i+1); //输入学生的成绩 scanf("%f",&stu[i].score); } // //讲学生的打印信息 // for (int i = 0; i < 2; ++i) // { // struct Student *p = &stu[i]; // printf("姓名:%s 学籍号:%s 成绩:%.2f\n",p->name,p->idNum,p->score); // } compare(stu,2); return 0; } void compare(struct Student stus[],int count) { float max = 0; struct Student *maxStu; for (int i = 0; i < count; ++i) { //取得学生的成绩 float score = stus[i].score; if (max < score) { max = score; maxStu = &stus[i]; } } if (stus[0].score == stus[1].score) { //讲学生的打印信息 for (int i = 0; i < 2; ++i) { struct Student *p = &stus[i]; printf("姓名:%s 学籍号:%s 成绩:%.2f\n",p->name,p->idNum,p->score); } } else printf("学生信息的识别:名字:%s 卷号:%s 成就:%.2f\n",maxStu->name,maxStu->idNum,maxStu->score); }


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值