题目:从键盘输入一个年份和月份,输出该月有多少天(考虑闰年, 闰年的条件是:(1)能被4整除,并且不能被100整除;(2)能被400整除)。
(提示:月份不在1-12都要输出"Input error!\n")
#include<stdio.h>
int main()
{
int year , day , month ;
printf("Input year,month:\n");
scanf("%d%d",&year ,&month);
if(month!=2)
{
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: printf("31 days\n"); break;
default: printf("Input errors \n"); break;
}
}
else if(month==2)
{
if(year%4==0&&year%100!=0||year%400==0)
printf("29 days\n");
else printf("28 days\n");
}
return 0;
}