【C语言程序设计第四版】例9-3代码
2021/9/19 14:04:46
本文主要是介绍【C语言程序设计第四版】例9-3代码,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
#include <stdio.h> struct student{ int num; char name[40]; int computer, english, math; double average; }; int update_score(struct student *p, int n, int num, int course, int score); int main(void){ int course, i , n, num, pos, score; struct student students[50]; printf("Input n:"); scanf("%d", &n); for (i = 0; i < n; i++) { printf("Input the info of No.%d:\n", i+1); printf("number:"); scanf("%d", &students[i].num); printf("name:"); scanf("%s", students[i].name); printf("math score:"); scanf("%d", &students[i].math); printf("english score:"); scanf("%d", &students[i].english); printf("computer socre:"); scanf("%d", &students[i].computer); students[i].average = (students[i].math + students[i].english + students[i].computer) / 3.0; } printf("input the number of the student to be updated"); scanf("%d", &num); printf("Choice of course:1.math 2.english 3.computer"); scanf("%d", &course); printf("Input the new sorce"); scanf("%d", &score); pos = update_score(students, n, num, course, score); if (pos == -1) { printf("Not found!\n"); }else{ printf("After update:\n"); printf("num\t math\t english\t computer \n"); printf("%d\t %d\t %d\t %d\n", students[pos].num, students[pos].math, students[pos].english, students[pos].computer); } return 0; } int update_score(struct student *p, int n, int num, int course, int score){ int i, pos; for (i = 0; i < n; i++, p++) { if (p->num == num) break; } if (i < n) { switch (course) { case 1: p ->math = score; break; case 2: p->english = score; break; case 3: p->computer =score; break; } pos = i; }else{ pos = -1; } return pos; }
这篇关于【C语言程序设计第四版】例9-3代码的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-07-06有没有什么开源的py项目可以对图像进行分类-icode9专业技术文章分享
- 2024-07-05feign默认connecttimeout和readtimeout是多少-icode9专业技术文章分享
- 2024-07-05idea控制台,日志太多,导致部分想看得日志被刷走 搜不到-icode9专业技术文章分享
- 2024-07-05The server selected protocol version Tls10 is not accepted by client preferences [TLs12]-icode9专业技术文章分享
- 2024-07-05怎么清理项目缓存-icode9专业技术文章分享
- 2024-07-04安装 Eyoucms详细图文教程-icode9专业技术文章分享
- 2024-07-04ueditor 复制文章时,图片的链接是一个下载图片地址,该如何处理?-icode9专业技术文章分享
- 2024-07-04怎样判断host有没有对wordpress有缓存呢-icode9专业技术文章分享
- 2024-07-04具有编译功能的系统make后,无法ssh连接-icode9专业技术文章分享
- 2024-07-04make后如何升级ssh-icode9专业技术文章分享