TA的每日心情 | 开心 2014-6-18 08:29 |
---|
签到天数: 14 天 [LV.3]偶尔看看II
滴水大师
 
- 积分
- 2345
|
题目
解决代码及点评
- <pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code"></pre><pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code"><pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code"><pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code">/*
- 6. 有10个学生,每个学生的数据包括学号、姓名、三门课的成绩,
- 从键盘输入10个学生数据,要求打印出三门课总平均成绩,
- 以及最高分的学生的数据(包括学号、 姓名、三门课成绩、平均分数)。
- */
- typedef struct Student
- {
- char num[20];
- char name[30];
- float chinese;
- float math;
- float english;
- }STU;
- #include <stdio.h>
- #include <stdlib.h>
- void main()
- {
- const int N = 10;
- STU *p;
- STU stu[N];
- p = stu;
- float avg;//每个学生的平均成绩
- float totalAvg = 0.0f;//总平均成绩
- float max = 0.0f;//保存平均值最大值
- float avgArr[N];//保存平均成绩的数组
- int index;//保存平均成绩最大值的角标
- for (int i = 0; i < N;i++) // 获取学生的详细信息
- {
- gets_s((p + i)->num);
- gets_s((p + i)->name);
- scanf_s("%f%f%f",&((p + i)->chinese),&((p + i)->math),&((p + i)->english));
- avg = ((p + i)->chinese + (p + i)->math + (p + i)->english) / 3;
- avgArr = avg;
- }
- for (int i = 0; i < N;i++) // 计算总成绩,获得最好成绩学生的下标
- {
- if (avgArr > max)
- {
- index = i;
- }
- totalAvg += avgArr;
- }
- printf("totalAvg = %f\n",totalAvg / N); // 打印平均成绩
- puts((p + index)->num);
- puts((p + index)->name);
- printf("chinese = %f\nmath = %f\nenglish = %f\navg = %f\n",
- (p + index)->chinese,(p + index)->math,(p + index)->english,avgArr[index]);
- system("pause");
- }</pre><br><br><br></pre></pre>
|
|