-
Notifications
You must be signed in to change notification settings - Fork 0
/
project_3.cpp
80 lines (80 loc) · 1.35 KB
/
project_3.cpp
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
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
void Max(int a[])
{
int i, max;
float sum = 0;
max = a[0];
for (i = 0; i < 8; i++)
{
if (a[i] > max)
{
max = a[i];
}
}
printf("最高分为:%d\n", max);
}
void Average(int a[])
{
int i;
float sum = 0, average;
for (i = 0; i < 8; i++)
sum = sum + a[i];
average = sum / 8;
printf("平均分为:%f\n", average);
}
void average_max_num(int a[],int s[])
{
int i = 0;
int ave_max = (a[0] + s[0]) / 2, p;
for (i = 0; i < 8; i++)
{
if ((a[i] + s[i]) / 2 > ave_max)
{
ave_max = (a[i] + s[i]) / 2;
p = i;
}
}
printf("平均成绩最高的学生的序号:%d\n", p+1);
}
void average_min_num(int a[], int s[])
{
int i = 0;
int ave_min = (a[1] + s[1]) / 2, k;
for (i = 0; i < 8; i++)
{
if ((a[i] + s[i]) / 2 < ave_min)
{
ave_min = (a[i] + s[i]) / 2;
k = i;
}
}
printf("平均成绩最低的学生的序号:%d\n", k+1);
}
int main()
{
//数学成绩
int i = 0;
int a[8] = {0};
printf("请输入8位同学的数学成绩:");
for (i = 0; i < 8; i++)
{
scanf("%d", &a[i]);
}
Max(a);
Average(a);
//英语成绩
int s[8] = {0};
printf("请输入8位同学的英语成绩:");
for (i = 0; i < 8; i++)
{
scanf("%d", &s[i]);
}
Max(s);
Average(s);
//平均成绩最高者的序号
average_max_num(a, s);
//平均成绩最低者的序号
average_min_num(a, s);
return 0;
}