/*
* Copyright (c) 2012, 烟台大学计算机学院 * All rights reserved. * 作 者:赵兰 * 完成日期:2012 年 10 月 31日 * 版 本 号:v1.0 * 输入描述:本月有几天 * 问题描述:输入年份、月份,即可求得本月一共多少天 * 程序输出:本月一共多少天 * 问题分析:先判断是否为闰年,然后根据所输入的月份进行输出 * 算法设计: */ 我的代码:
#include <iostream>
#include <Cmath>
using namespace std;
int main(){
int year,month;
cout<<"请输入年月:";
cin>>year>>month;
if(month>12){
cout<<"输入有误!请重新输入!"<<endl;}
else{
if(month==2){
if(year%4==0 && year%100!=0||year%400==0) //判断是否是闰年
{
cout<<"该月有29天"<<endl;
}
else
{
cout<<"该月有28天"<<endl;
}
}
else
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12) //一系列的判断条件
cout<<"该月有31天"<<endl;
else
cout<<"该月有30天"<<endl;
}
return 0;
}
输出结果: