编译代码
/***********************
**项目【2.1】本月有几天?**
**题目:用switch语句输入年份和月份,输出本月有几天
**作者:李坤**
************************/
#include<stdio.h>
int main()
{
int year,month,days;
scanf("%d %d",&year,&month);
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
days=31;
printf("%d days\n",days);
break;
case 4:
case 6:
case 9:
case 11:
days=30;
printf("%d days\n",days);
break;
case 2:
switch((year%4&&(year%100!=0))||year%400)
{
case 0:
days=28;
printf("%d days\n",days);
break;
default:
days=29;
printf("%d days\n",days);
break;
}
break;
default:
printf("error\n");
break;
}
return 0;
}
运行结果