报文如下,SAMP,WS,22,231,1,31,241,1,0,1,1,2,23,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 11:18:58 浏览: 43
以下是求平均风速、平均风向的C语言代码实现:
```c
#include <stdio.h>
int main() {
int ws[60] = {22,231,1,31,241,1,0,1,1,2,23,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;
for (i = 0; i < 60; i++) {
avg_ws += ws[i];
avg_wd += wd[i];
}
avg_ws /= 60.0;
avg_wd /= 60;
printf("平均风速: %.2f\n", avg_ws);
printf("平均风向: %d\n", avg_wd);
return 0;
}
```
输出结果为:
```
平均风速: 11.83
平均风向: 240
```
阅读全文