-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrain.c
61 lines (49 loc) · 1.56 KB
/
rain.c
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
#include <stdio.h>
#define MONTHS 12
#define YEARS 5
int main()
{
const float rain[YEARS][MONTHS] =
{
{4.3, 4.3, 4.3, 3.0, 3.0, 2.0, 1.2, 0.2, 0.2, 0.4, 2.4, 3.5, 6.6},
{8.5, 2.2, 1.2, 1.6, 2.4, 0.0, 5.2, 0.9, 0.3, 0.9, 1.4, 7.3, 2.1},
{9.1, 8.8, 5.5, 2.6, 4.4, 3.2, 4.3, 5.6, 7.9, 5.4, 6.2, 2.5, 5.6},
{7.2, 5.3, 6.5, 3.0, 3.0, 2.0, 1.2, 1.6, 2.4, 0.0, 5.2, 0.9, 1.4},
{3.0, 3.0, 2.0, 1.2, 1.6, 2.4, 0.0, 5.2, 0.9, 0.3, 9.1, 8.8, 5.5},
{1.2, 1.6, 2.4, 0.0, 5.2, 1.2, 1.6, 2.4, 0.0, 5.2, 6.5, 3.0, 3.0}
};
int year, month;
float subtot, total;
printf(" YEAR RAINFALL (inches)\n");
for(year = 0, total = 0; year < YEARS; year++)
{
for(month = 0, subtot = 0; month < MONTHS; month++)
subtot += rain[year][month];
printf("%5d %15.1f\n", 2013 + year, subtot);
total += subtot;
}
printf("\n %d年到%d年%d年的总降水量为%.1f,平均每年降水量为%.1f.\n\n", 2013, 2013 + YEARS - 1, YEARS, total, total / YEARS );
printf("每月平均降水量为\n\n");
printf(" Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec\n");
for(month = 0; month < MONTHS; month++)
{
for(year = 0, subtot = 0; year < YEARS; year++)
subtot += rain[year][month];
printf("%4.1f ", subtot / YEARS);
}
printf("\n");
return 0;
}
/*
Output:
YEAR RAINFALL (inches)
2013 28.8
2014 31.9
2015 65.5
2016 38.3
2017 37.5
2013年到2017年5年的总降水量为202.0,平均每年降水量为40.4.
每月平均降水量为
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
6.4 4.7 3.9 2.3 2.9 1.9 2.4 2.7 2.3 1.4 4.9 4.6
*/