编写程序的目的就是输入年份和月份,输出对应的天数。
我编写程序的目的就是输入年份和月份,判断对应的天数。if结构中嵌套了switch结构,但是总有错,请大神指正。#include<stdio.h>
#include<math.h>
void main()
{int y,m;
printf("please input y,m:");
scanf("%d %d",&y,&m);
if(y%4==0&&y%100!=0||y%400==0)
switch(m)
{case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:printf("31天\n");break;
case 2:printf("29天\n");break;
case 4:
case 6:
case 9:
case 11:printf("30天\n");break;}
else
{switch(m)
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:printf("31天\n");break;
case 2:printf("28天\n");break;
case 4:
case 6:
case 9:
case 11:printf("30天\n");break;
}
}