- /*
- *程序的版权和版本声明部分:
- *Copyright(c)2013,烟台大学计算机学院学生
- *All rights reserved.
- *文件名称:
- *作者:王雅萍
- *完成日期:2013年 10月31日
- *版本号:v1.0
- *对任务及求解方法的描述部分:
- *输入描述:输入年月,显示本月多少天
- *问题描述:输入年月,显示本月多少天
- *程序输出:本月天数
- *问题分析:
- *算法设计: 先判断是否闰年
- */
#include<iostream>
using namespace std;
int main()
{
int year,month,day;
cout<<"请输入年,月:"<<endl;
cin>>year>>month;
if(year%4==0&&year%100!=0||year%400==0) //先讨论是不是闰年
{
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
day=31;
else if(month==4||month==6||month==9||month==11)
day=30;
else
day=29; //闰年2月有29天
}
else
{
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
day=31;
else if(month==4||month==6||month==9||month==11)
day=30;
else
day=28;
}
cout<<"本月有"<<day<<"天"<<endl;
return 0;
}
心得体悟:时间好紧呀。。。