/*
* Copyright(c)2011,烟台大学计算机学院
* All right reserved.
* 文件名称:test.cpp
* 作者: 张凯
* 完成日期:2013年10月16日
* 版本号: v1.0
* 输入描述:输入年月
* 问题分析:先判断是闰年还是平年然后在判断月份
*/
#include <iostream>
using namespace std;
int main ()
{
int year,month;
cout<<"请输入年月";
cin>>year>>month;
if(year%4==0&&year%100!=0||year%400==0)
{
switch(month)
{case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:cout<<"31天"<<endl;break;
case 2:cout<<"29天"<<endl;break;
default:cout<<"30天"<<endl;
}
}
else
{
switch(month)
{case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:cout<<"31天"<<endl;break;
case 2:cout<<"28天"<<endl;break;
default:cout<<"30天"<<endl;
}
}
return 0;
}
运行结果(如下图)
心得体会:用switch简单多了