c语言练习 二维数组 年平均降水量 月平均降水量

2021-06-17 01:03

阅读:667

标签:printf   1.2   二维数组   define   main   ++   bsp   二维   average   


#define YEARS 5
#define MONTHES 12


int
main(void) { const float rain[YEARS][MONTHES] = { {4.3,4.3,4.3,3.0,2.0,1.2,0.2,0.2,0.4,2.4,3.5,6.6}, {8.5,8.2,1.2,1.6,2.4,0.0,5.2,0.9,0.3,0.9,1.4,7.3}, {9.1,8.5,6.7,4.3,2.1,0.8,0.2,0.2,1.1,2.3,6.1,8.4}, {7.2,9.9,8.4,3.3,1.2,0.8,0.4,0.0,0.6,1.7,4.3,6.2}, {7.6,5.6,3.8,2.8,3.8,0.2,0.0,0.0,0.0,1.3,2.6,5.2} }; float rain_year=0; int i; int j; float rain_month = 0; for (i = 0; i ) { for (j = 0; j ) { rain_year = rain_year + rain[i][j]; } printf("sum rain of year %d is %.1f,average rain is %.1f\n", i + 1,rain_year,rain_year/MONTHES); rain_year = 0; } for (j = 0; j ) { for (i = 0; i ) { rain_month = rain_month + rain[i][j]; } printf("%d month rain is %.1f\n", j + 1, rain_month/YEARS); } return 1;

感想:二维数组总是感觉没有那么一维数组直观,写起来比较费脑子,要多写啊。

 

c语言练习 二维数组 年平均降水量 月平均降水量

标签:printf   1.2   二维数组   define   main   ++   bsp   二维   average   

原文地址:https://www.cnblogs.com/yfish/p/9723214.html


评论


亲,登录后才可以留言!