任务七:输出年月的月份天数
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;
}
本文介绍了一个简单的C++程序,用于计算并输出指定年月的天数,包括判断是否为闰年的逻辑。
3427

被折叠的 条评论
为什么被折叠?



