用java或c语言编写真值表,C语言编写程序

满意答案

dcebd7a0de6265b6ccae5ead692f1eab.png

hrt445310

2018.10.18

#include 

#include 

#include 

int main()

{

int temperature;  //温度

int weather;      //天气

char str_weather[5];

int wind;         //风

srand((unsigned)time(0));//初始化随机种子

temperature=rand()%63-20; //获取-20到42的随机数

while(1)

{

weather=rand()%3;//获取天气情况:0为雨,1为雪,2为晴

if(temperature<0 && weather==0) //如果温度小于0度并且天气为雨,则重新获取

{

continue;

}

switch(weather)

{

case 0:

strcpy(str_weather,"雨");

break;

case 1:

strcpy(str_weather,"雪");

break;

case 2:

strcpy(str_weather,"晴");

break;

}

break;  //如果符合规则,则退出循环

}

wind=rand()%13;//获取风级:0-12

printf("今天温度:%d  天气:%s  风级:%d级\n",temperature,str_weather,wind);

return 0;

}

00分享举报

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值