您的位置:首页 > 编程语言 > C语言/C++

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

2016-04-07 08:56 274 查看
/*

 *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;

}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c语言