第三周第二篇 本月有几天?

来源:互联网 发布:php 能和sql 编辑:程序博客网 时间:2024/05/26 12:57
/*
 *Copyrigth(c)2015,烟台大学计算机学院
 *All rights reserved.
 *文件名称:main.cpp
 *作者:汤善晔
 *完成日期:2016年4月1日
 *版本号:CodeBlocks12.11
 *
 *问题描述:编程序,输入年份和月份,输出本月有多少天。
 *输入描述:输入两个数,年和月。
 *程序输出:输出一个数,本月天数。
*/
#include<iostream>
using namespace std;
int main()
{
    int year,month;
    cin>>year;
    cin>>month;
    if(year%4==0&&year%100!=0||year%400==0)
    {
        if(month==2)
            cout<<"29\n";
        else if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
            cout<<"31\n";
        else
            cout<<"30\n";
    }
    else
    {
        if(month==2)
           cout<<"28\n";
        else if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
            cout<<"31\n";
        else
            cout<<"30\n";
    }
    return 0;
}
0 0
原创粉丝点击