1、
#include <stdio.h>
int main(void)
{
int i;
puts("please input a month.");
printf("month i: "); scanf("%d",&i);
if (i >= 3 && i <= 5)
{
printf("%d is spring\n",i);
}
else
{
if (i >= 6 && i <= 8)
{
printf("%d is summer\n",i);
}
else
{
if (i >= 9 && i <= 11)
{
printf("%d is autumn\n",i);
}
else
{
if (i == 12 || i == 1 || i == 2)
{
printf("%d is winter\n",i);
}
else
{
printf("%d is not exist!!!!\a\n");
}
}
}
}
return 0;
}
2、等价于1
#include <stdio.h>
int main(void)
{
int i;
puts("please input a month.");
printf("month i: "); scanf("%d",&i);
if (i >=3 && i <= 5)
printf("%d is spring!\n");
else if (i >= 6 && i <= 8)
printf("%d is summer!\n");
else if (i >= 9 && i <= 11)
printf("%d is autumn1\n");
else if (i == 12 || i == 1 || i == 2)
printf("%d is winter!\n");
else
printf("%d is not exist!!!\a\n");
return 0;
}
原文:https://www.cnblogs.com/liujiaxin2018/p/14199629.html