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;
}
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;
}
相关文章推荐
- 第一周:项目1 使用switch结构编写函数根据月份输出对应的季节
- 2015C++第二周,任务七:以不同的形式输出日期,月份以英文显示,涉及类,构造函数等等,并限定月份只有12个月,日期与实际情况相同,如果输入错误则显示为0.
- 输入年月,输出该月份的日历页
- java输入年份和月份,输出天数
- 用户从键盘输入月份,使用switch语句输出该月份的天数
- 输入年份和月份,输出月份天数
- 第二章作业P51.10(输入年号和月份,输出这一年的该月的天数。
- 51页 10题 输入年号和月份,输出这一年该月的天数
- 输入年份月份输出对应的天数
- Java通过年月,计算月份天数。
- 如何根据年月计算月份最大天数
- vb.net 交错 处理 一年中的月份天数的输出
- 编程实现统计某年某月份的天数。 例如:输入:2017.7 输出:31天
- 根据用户输入年和月份值,输出对应月份的天数。
- 8.4 编写一个日期类,实现日期的加天数、减天数和输出操作(不考虑闰年的情况, 2 月份固定为 28 天)。
- delphi 输入年月判断天数,判断指定年份与月份判断当月有多少天
- 输出月份的天数
- 用户从键盘输入月份,使用switch语句输出该月份的天数
- Java通过年月,计算月份天数。
- 输入年月输出该月天数