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

2015C++第一周,任务七:输出年月的月份天数

2015-01-17 22:30 253 查看
任务七:输出年月的月份天数
1-51
#include
"stdafx.h"
#include
<stdio.h>
#include<iostream>
#include<string.h>
using namespacestd;
int main()
{
int year, month, days, leap;
cout << "请输入年月:"<< endl;
cin>> year >> month;
switch(month){//选择月份
case1:
case3:
case5:
case7:
case8:
case10:
case12:
days =31; break;
case4:
case6:
case9:
case11:
days =30; break;
case2:

if(year % 400 == 0)//年份能被400整除的是闰年
leap= 1;
elseif(year % 4 == 0 && year % 100 != 0)//年份能被4整除,但不能被100整除的是闰年
leap= 1;
else
leap= 0;
default:
cout<< "输入有误!" << endl;
if(leap) days = 29;
else days = 28;

}
cout<< year << "年"<< month <<
"月"<<
" 该月的天数为:"<<days << endl;

return0;

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