/*2015,烟台大学计算机与控制工程学院
*All rightreserved.
*文件名称:test.cpp
*作 者:张明宇
*完成日期:2016年3月20日
*/
问题及代码:
编程序,输入年份和月份,输出本月有多少天。合理选择分支语句完成设计任务。
样例输入:2004 2,输出结果 1:本月29 天
样例输入:2010 4,输出结果 2:本月30 天
#include <stdio.h>
#include <stdlib.h>
int main()
{
int year,month;
scanf("%d %d",&year,&month);
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
printf("本月有三十一天");
break;
case 2:
if((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0))
{
printf("本月有二十九天");
}
else
{
printf("本月有二十八天");
}
break;
case 4:
case 6:
case 9:
case 11:
printf("本月有三十天");
break;
default:
printf("您的输入不正确!");
break;
}
return 0;
}