if....else if的简单运用

用if...else  if判断季节

3,4,5    x月是春季

6,7,8    x月是夏季

9,10,11  x月是秋季

12,1,2    x月是冬季


int month;

printf("请输入月份: "); 

scanf("%d",&month);

if (month <= 5 && month >= 3) {

printf("%d月是春季\n",month);

}else if (month <= 8 && month >= 6){

printf("%d月是夏季\n",month);

}else if (month <= 11 && month >= 9){

printf("%d月是秋季\n",month);

}else if (month <= 2 && month >= 1){

printf("%d月是冬季\n",month);

}else if (month == 12){

printf("%d月是冬季\n",month);

}else{

printf("%d月,你确定一年中有这个月???\n",month);

}

你可能感兴趣的:(if....else if的简单运用)