1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
| #include <stdio.h>
#define N 100
#define NAME "LANCE.MOE"
const char *sjyGrade(float score) {
// 获取成绩等第
if (score < 60)
return "不及格";
else if (score < 70)
return "及格";
else if (score < 80)
return "中等";
else if (score < 90)
return "良好";
return "优秀";
}
int main() {
// 题目要求定义的变量
int sjyNum = 0;
char sjyName[N][20]; // 存储姓名
int sjyScore[N][5]; // 存储五科分数
float sjyAvg[N]; // 每人平均分
float sjySubj[5] = { 0, 0, 0, 0, 0 }; // 全员五门课程平均分
int sjyIndex[N];
//自己的变量
char sbjname[5][5] = { "语文","数学","政治","英语","综合" };
int n = 0, m = 0; // 循环变量 vb6有for作用域bug所以放最前面
// 输出表头
printf("%s的学生成绩处理程序\n", NAME);
printf("===================================\n");
// 输入学生人数
printf("请输入要处理的学生的人数(3~100):");
scanf("%d", &sjyNum);
if (sjyNum < 3 || sjyNum > N) {
printf("您输入的要处理的学生人数不符合要求!");
getchar();
return 0;
}
// 输入学生数据
for (n = 0; n < sjyNum; ++n) {
printf("请输入第%d名学生的姓名:", n + 1);
scanf("%s", &sjyName[n]);
sjyAvg[n] = 0.0f; // 总分设置为0
for (m = 0; m < 5; ++m) {
printf("%s分数:", sbjname[m]);
scanf("%d", &sjyScore[n][m]);
sjyAvg[n] += sjyScore[n][m];
}
sjyAvg[n] /= 5;
printf("第%d名学生成绩输入完毕,平均分%.1f!\n", n + 1, sjyAvg[n]);
printf("===================================\n");
}
// 计算每个学生名次
for (n = 0; n < sjyNum; ++n) {
sjyIndex[n] = 0;
for (m = 0; m < sjyNum; ++m)
if (sjyAvg[n] > sjyAvg[m])
++sjyIndex[n];
sjyIndex[n] = sjyNum - sjyIndex[n];
}
// 输出表头
printf("%s的学生成绩处理程序\n", NAME);
printf("===================================\n");
printf("姓名\t");
for (n = 0; n < 5; ++n)
printf("%s\t", sbjname[m]);
printf("平均分\t级别\t名次\n");
// 输出每个学生数据
for (n = 0; n != sjyNum; ++n)
printf("%s\t%d\t%d\t%d\t%d\t%d\t%.1f\t%s\t%d\n", sjyName[n], sjyScore[n][0], sjyScore[n][1], sjyScore[n][2], sjyScore[n][3], sjyScore[n][4], sjyAvg[n], sjyGrade(sjyAvg[n]), sjyIndex[n]);
printf("-----------------------------------\n");
// 计算各科平均分
for (m = 0; m < 5; ++m) {
for (n = 0; n < sjyNum; ++n)
sjySubj[m] += float(sjyScore[n][m]);
sjySubj[m] /= sjyNum;
}
// 输出各科平均分
printf("平均\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\n", sjySubj[0], sjySubj[1], sjySubj[2], sjySubj[3], sjySubj[4]);
// 结束程序
getchar();
return 0;
}
|