博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
谭浩强C程序设计(第四版)例题中的代码优化
阅读量:4644 次
发布时间:2019-06-09

本文共 1243 字,大约阅读时间需要 4 分钟。

eg:9.7 有n个结构体变量,内含学生学号,姓名和3门课成绩,要求输出平均成绩最高的学生的信息(内含学生学号,姓名和3门课成绩和平均成绩)。

2015-01-2022:25:34

1 #include
2 #define N 2 3 4 struct Student 5 { 6 int num; 7 char name[20]; 8 float score[3]; 9 float aver;10 };11 12 void input(struct Student *stu)13 {14 int i;15 printf("input the student's information:\nname,num,three score\n");16 for(i=0;i
name,&stu->num ,19 &stu->score[0],&stu->score[1],&stu->score[2]);20 stu->aver=(stu->score[0]+stu->score[1]+stu->score[2])/3;21 }22 }23 24 struct Student *Max(struct Student *stu)25 {26 int i;27 int m=0;28 for(i=0;i
stu[m].aver)31 {32 m=i;33 }34 }35 return &stu[m];36 }37 38 void print_stu(struct Student *stud)39 {40 printf("\nThe average scores of the top students is:\n");41 printf("num:%d\nname:%s\nthe three subject:%5.1f,%5.1f,%5.1f\nthe aver score:%6.2f\n",stud->num,stud->name,stud->score[0],stud->score[1],stud->score[2],stud->aver); 42 }43 44 int main()45 {46 struct Student stu[N];47 struct Student *p = stu;48 input(p);49 print_stu(Max(p));50 return 0;51 }

 

转载于:https://www.cnblogs.com/wumo66/p/4237609.html

你可能感兴趣的文章
CSS选择器总结
查看>>
mysql中sql语句
查看>>
head/tail实现
查看>>
sql语句的各种模糊查询语句
查看>>
vlc 学习网
查看>>
Python20-Day05
查看>>
Real World Haskell 第七章 I/O
查看>>
C#操作OFFICE一(EXCEL)
查看>>
【js操作url参数】获取指定url参数值、取指定url参数并转为json对象
查看>>
ABAP 程序间的调用
查看>>
移动端单屏解决方案
查看>>
web渗透测试基本步骤
查看>>
使用Struts2标签遍历集合
查看>>
angular.isUndefined()
查看>>
第一次软件工程作业(改进版)
查看>>
网络流24题-飞行员配对方案问题
查看>>
Jenkins 2.16.3默认没有Launch agent via Java Web Start,如何配置使用
查看>>
引入css的四种方式
查看>>
iOS开发UI篇—transframe属性(形变)
查看>>
3月7日 ArrayList集合
查看>>