结构体指针例题(三)
来源:互联网 发布:js if判断多个条件 编辑:程序博客网 时间:2024/05/01 00:08
【题目】有n个结构体变量,内含学生学号、姓名和3门课程的成绩。要求输出平均成绩最高的学生的信息(包括学号、姓名、3门课程成绩和平均成绩)。
#include<stdio.h>#define N 3 //学生数为3struct student{long num;char name[20];int score[3];float aver;}stu[N];int main(){void input(struct student stu[]);struct student max(struct student stu[]);void print(struct student stu); struct student *p=stu;input(p);print(max(p));return 0;}void input(struct student stu[]){int i;printf("请输入%d个学生的信息(学号、姓名、三门课成绩):\n",N);for(i=0;i<N;i++){scanf("%ld %s %d %d %d",&stu[i].num,stu[i].name,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);stu[i].aver=(stu[i].score[0]+stu[i].score[1]+stu[i].score[2])/3.0;}}struct student max(struct student stu[]){int i,m=0;for(i=1;i<N;i++)if(stu[i].aver>stu[m].aver) m=i;return stu[m];}void print(struct student stu){printf("\n成绩最高的学生是:\n");printf("学号:%ld\n姓名:%s\n三门课成绩:%d %d %d\n平均成绩:%5.2f\n\n", stu.num,stu.name,stu.score[0],stu.score[1],stu.score[2],stu.aver);}
- 结构体指针例题(三)
- 结构体指针例题(一)
- 结构体指针例题(二)
- c语言例题指针三
- 用指针处理链表例题(三)
- C语言结构体变量和结构体变量的指针作函数参数例题
- 文件例题(三)
- 结构体初始化 访问的三种方式(结构体指针)
- 【经典例题】抓交通肇事犯答案(结构体版)
- 紫书章五例题八 命令 UVA 400 (排序+结构体)
- 结构经典例题,用上了typedef 再进行指针优化
- 计算机网络相关例题(三)
- (十七)结构体指针
- C开发lua模块(三) --- 返回userdata和结构体指针
- c语言结构体和联合体例题
- 结构体,对例题的总结
- 信号量(三) 经典例题(二)
- c++例题 构造函数(三)
- Linux 磁盘旧RAID 信息 导致不能格式化 和mount 的解决方法
- HTML中点击TABLE列头实现排序功能
- IOS NSRunLoop的进一步理解
- php中的单引号与双引号作用详解
- linux重装oracle
- 结构体指针例题(三)
- startx 启动过程
- 字符编码笔记:ASCII,Unicode和UTF-8
- Python strip lstrip rstrip使用方法
- 用纯JAVA语言编程读取MAC地址的实现
- 欧拉角与旋转
- cocos2d-x学习相关链接
- android:自动横竖屏切换在各种需求下的处理
- ecshop后台新功能权限的添加