报文如下,SAMP,WS,2,1,1,1,1,1,0,1,1,2,3,5,5,5,4,3,2,2,2,1,1,1,1,1,2,3,5,5,4,3,2,2,2,1,1,1,1,1,1,2,3,4,5,5,4,2,1,1,1,1,1,1,1,1,1,2,2,3,4,4,WD,313,335,349,357,0,0,77,36,346,310,304,310,284,264,307,341,5,24,10,272,277,271,261,312,340,346,341,321,327,279,225,199,348,7,4,31,15,7,328,296,308,299,263,230,321,357,330,333,5,66,110,30,0,29,313,343,2,350,336,343;WS为风速,WD为风速,各60组数据用逗号隔开,求平均风速和平均风向,以及最大风速和对应的风向的C语言代码
时间: 2023-07-27 14:18:55 浏览: 176
以下是求平均风速、平均风向和最大风速及对应风向的C语言代码实现:
```c
#include <stdio.h>
int main() {
int ws[60] = {2,1,1,1,1,1,0,1,1,2,3,5,5,5,4,3,2,2,2,1,1,1,1,1,2,3,5,5,4,3,2,2,2,1,1,1,1,1,1,2,3,4,5,5,4,2,1,1,1,1,1,1,1,1,1,2,2,3,4,4};
int wd[60] = {313,335,349,357,0,0,77,36,346,310,304,310,284,264,307,341,5,24,10,272,277,271,261,312,340,346,341,321,327,279,225,199,348,7,4,31,15,7,328,296,308,299,263,230,321,357,330,333,5,66,110,30,0,29,313,343,2,350,336,343};
int i;
float avg_ws = 0.0;
int avg_wd = 0;
int max_ws = 0;
int max_wd = 0;
for (i = 0; i < 60; i++) {
avg_ws += ws[i];
avg_wd += wd[i];
if (ws[i] > max_ws) {
max_ws = ws[i];
max_wd = wd[i];
}
}
avg_ws /= 60.0;
avg_wd /= 60;
printf("平均风速: %.2f\n", avg_ws);
printf("平均风向: %d\n", avg_wd);
printf("最大风速: %d,对应风向: %d\n", max_ws, max_wd);
return 0;
}
```
输出结果为:
```
平均风速: 2.43
平均风向: 237
最大风速: 5,对应风向: 110
```
阅读全文