/*说明:
闰年的 2 月份有 29 天
普通闰年: 能被 4 整除但不能被 100 整除的年份为
世纪闰年: 能被 400 整除*/
#include <iostream>
#include <string>
#include <Windows.h>
using namespace std;
int main(void) {
int year;
int month;
int days;
bool bark;
cout << "请输入年份:"<<endl;
cin >> year;
cout << "请输入月份:"<<endl;
cin >> month;
if (year % 400 == 0) {
bark = true;
}
else if (year % 4 == 0 && year % 100 != 0) {
bark = true;
}
else
{
bark = false;
}
switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
{days = 31;
break;
}
case 2:
{days = bark ? 29 : 28;
break; }
case 4:
case 6:
case 9:
case 11:
{days = 30;
break; }
default:
break;
}
cout << year << "年" << month << "月有" << days << "天";
system("pause");
return 0;
}
运行结果: