/*
*Copyright(C) 2016,计算机与控制工程学院
*All rights reserved.
*文件名:test.cpp
*作者:张志新
*完成日期:2016年3月15日
*版本号:v1.0
*
*问题描述:输入年份和月份,输出本月有多少天。
*输入描述:年份与月份。
*程序输出:本月天数。
*/
#include<iostream>
using namespace std;
int main()
{
int year,mouth;
cout<<"请输入年份和月份: ";
cin>>year>>mouth;
if(mouth==4||mouth==6||mouth==8)
cout<<"本月30天\n";
else if(mouth==2)
{
if(year%4==0&&year%100!=0||year%400==0)
cout<<"本月29天\n";
else
cout<<"本月28天\n";
}
知识点总结:
这个程序中运用了if语句的嵌套,以及闰年和平年的计算。
学习心得:
在做这个题时一开始运用了比较麻烦的方法,先判断平闰年然后在判断月,在做的过程发现先判断月在判断年会更简单一些。