计算某年某月有几天

来源:互联网 发布:淘宝美工装修助手 编辑:程序博客网 时间:2024/05/07 12:51

#include <iostream>

using namespace std;
int main()
{
    int year,month;
    double a,b,c;
    cin>>year>>month;
    a=year%4;
    c=year%100;
    b=year%400;
    if(((a==0) && (c!=0)) || (b==0))
    {
        switch(month)
        case 1:
        case 3:
        case 5:
        case 7:
        case 9:
        case 11:
        {
            cout <<"本月有31天"<<endl;
            break;
        }
        switch(month)
        case 4:
        case 6:
        case 8:
        case 10:
        case 12:
        {
            cout <<"本月有30天"<<endl;
            break;
        }
        switch(month)
        case 2:
            {
                cout <<"本月有29天"<<endl;
                break;
            }
    }
    else
    {
        switch(month)
        case 1:
        case 3:
        case 5:
        case 7:
        case 9:
        case 11:
        {
            cout <<"本月有31天"<<endl;
            break;
        }
        switch(month)
        case 4:
        case 6:
        case 8:
        case 10:
        case 12:
        {
            cout <<"本月有30天"<<endl;
            break;
        }
        switch(month)
        case 2:
         {
             cout <<"本月有28天"<<endl;
             break;
         }
    }
    return 0;
}

0 0