C语言完美演绎9-14

/* 范例:9-14(以VC++执行,请参考范例光盘源代码中的说明)*/

#include <stdio.h>

#include <conio.h>

#include <string.h>

struct Scale /* 记录每个人各科成绩 */

{

char name10;

int chi_sco;

int eng_sco;

int math_sco;

};

struct /* 记录各科总分 */

{

int chi;

int eng;

int math;

}Sum={0,0,0}; /* 全局,可省略初值0 */

/* 记录chi,eng,math最高分 */

struct

{

int max_chi; /* 最高分数 */

int max_eng;

int max_math;

char name_chi10; /* 最高分者的姓名 */

char name_eng10;

char name_math10;

}TopGuy;

void main(void)

{

struct Scale student50; /* 定义结构数组 */

int count=0;

char reTry='y';

do

{

printf("\n请输入学生姓名:");

scanf("%s",studentcount.name);

printf("请输入语文成绩:");

scanf("%d",&studentcount.chi_sco);

printf("请输入英文成绩:");

scanf("%d",&studentcount.eng_sco);

printf("请输入数学成绩:");

scanf("%d",&studentcount.math_sco);

Sum.chi += studentcount.chi_sco; /* 各科计分 */

Sum.eng += studentcount.eng_sco;

Sum.math += studentcount.math_sco;

if(studentcount.chi_sco > TopGuy.max_chi)

{

TopGuy.max_chi = studentcount.chi_sco;

strcpy(TopGuy.name_chi,studentcount.name);

}

if(studentcount.eng_sco > TopGuy.max_eng)

{

TopGuy.max_eng = studentcount.eng_sco;

strcpy(TopGuy.name_eng,studentcount.name);

}

if(studentcount.math_sco > TopGuy.max_math)

{

TopGuy.max_math = studentcount.math_sco;

strcpy(TopGuy.name_math,studentcount.name);

}

printf("是否继续输入?(请输入Y/N或y/n)");

do

{

reTry = getche();

}while((reTry!='Y')&&(reTry!='y')&&(reTry!='N')&&(reTry!='n'));

count++;

}while((reTry=='y')||(reTry=='Y'));

if(count>0)

{

clrscr();

printf("共输入%d人\n",count);

printf("语文平均%5.2f分,最高分%d分:%s\n", \

((float)Sum.chi/(float)count), \

TopGuy.max_chi,TopGuy.name_chi);

printf("英文平均%5.2f分,最高分%d分:%s\n", \

((float)Sum.eng/(float)count), \

TopGuy.max_eng,TopGuy.name_eng);

printf("数学平均%5.2f分,最高分%d分:%s\n", \

((float)Sum.math/(float)count), \

TopGuy.max_math,TopGuy.name_math);

}

getche();

}

程序执行结果:(假设输入两人分数:A,90,40,100、B,65,99,70)

共输入2人

语文平均77.50分,最高分90分:A

英文平均69.50分,最高分99分:B

数学平均85.00分,最高分100分:A

相关推荐
库玛西1 小时前
现代 C++ 智能指针全景指南:从 RAII 思想到工业级实践
c语言·开发语言·c++·笔记·面试
AC赳赳老秦1 小时前
风控岗应用:OpenClaw 采集公开司法与经营异常数据,自动生成企业风险评估报告
大数据·c语言·数据库·人工智能·python·php·openclaw
程序员与背包客_CoderZ3 小时前
Linux D-Bus通信协议详解:从入门到C/C++编码实战
linux·服务器·c语言·c++·嵌入式硬件·嵌入式软件·dbus
嵌入式阿蔡4 小时前
HAL库 vs LL库 vs 寄存器:到底用哪个?
c语言·stm32·单片机·嵌入式硬件·嵌入式实时数据库
Yyyyyy~4 小时前
【C】C语言常见概念
c语言
嵌入式阿蔡6 小时前
CAN总线入门:从协议帧到STM32实战
c语言·stm32·单片机·嵌入式硬件·嵌入式实时数据库
LONGZETECH6 小时前
无人机组装调试实训高损耗痛点分析与虚拟仿真教学落地方案
c语言·开发语言·架构·无人机
luj_17687 小时前
大航海时代:沉浸式财商实战沙盒
c语言·开发语言·网络·经验分享·算法
Navigator_Z7 小时前
LeetCode //C - 1200. Minimum Absolute Difference
c语言·算法·leetcode
LuminousCPP8 小时前
数据结构基础篇(二):顺序表与链表全方位对比|从内存布局到 CPU 缓存理解底层差异
c语言·数据结构·经验分享·链表·缓存