用C语言编写一个程序输入昨天的平均气温、平均湿度和天气。其中气温是整数(摄氏-50到50度),湿度也是整数(0-100),天气是1(sunny 晴天)、2(cloudy 阴天)、3(rainy 雨天)中的一种。输入数据中间用空格隔开。
时间: 2023-05-12 21:03:31 浏览: 257
以下是用C语言编写的程序,可以输入昨天的平均气温、平均湿度和天气:
```c
#include <stdio.h>
int main() {
int temperature, humidity, weather;
printf("请输入昨天的平均气温、平均湿度和天气(用空格隔开):");
scanf("%d %d %d", &temperature, &humidity, &weather);
printf("昨天的平均气温是%d摄氏度,平均湿度是%d%%,天气是", temperature, humidity);
switch (weather) {
case 1:
printf("晴天\n");
break;
case 2:
printf("阴天\n");
break;
case 3:
printf("雨天\n");
break;
default:
printf("未知\n");
break;
}
return 0;
}
```
注意,这个程序假设输入的数据都是合法的,没有进行错误处理。如果需要,可以在程序中添加相应的错误处理代码。