第1个回答 推荐于2016-04-20
#include <stdio.h>
void main()
{ int year,month,day; //定义三个整型变量表示年份,月份,天数
printf("input year and month:\n"); //要求输入年份和月份
scanf("%d%d",&year,&month); //将输入的年月放在变量中
switch (month) //对月份分类讨论
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: day=31; break; //31天的月份
case 4:
case 6:
case 9:
case 11: day=30; break; //30天的月份
case 2: if ((year % 4 == 0 && year % 100 != 0)
|| year % 400 == 0)
day = 29; //闰年二月28天
else day = 28; break; //非闰年29天
}
if (month < 1 || month >12) printf("error\n");//月份错误,error
else printf("这一月的天数是%d天\n",day); //输出天数
}本回答被提问者采纳