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

C++求某年某月的天数

2016-03-23 18:59 302 查看
文件:app.cpp

作者:杨栋

问题描述:输入某年某月,查询该月天数

#include<iostream>

using namespace std;

int main()

{

int year,month;

cout<<"请输入年份和月份(中间用空格隔开)\n";

cin>>year>>month;

if(year%4==0&&year%100!=0||year%400==0)

switch(month)

{

case 1:

case 3:

case 5:

case 7:

case 8:

case 10:

case 12:

cout<<"本月31天";

break;

case 2:

cout<<"本月29天";

break;

default:

cout<<"本月30天";

}

else

switch(month)

{

case 1:

case 3:

case 5:

case 7:

case 8:

case 10:

case 12:

cout<<"本月31天";

break;

case 2:

cout<<"本月28天";

break;

default:

cout<<"本月30天";

}

return 0;

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