问题分析:每年的1,3,5,7,8,10,12月份是31天,4,6,9,11月份是30天,2月要考虑润年的情况,如果不是润年,2月是28天,如果是润年,2月是29天。

润年的条件:如果年份能被4整除但不能被100整数,或者能被400整数,那就是润年。

#include<iostream>
#include<string>
#include <ctype.h>
using namespace std;
int main()
{
 
        int year, month;
	cout << "输入年和月,空格分开:" << endl;
	cin >> year >> month;
	if (month<1||month>12)
	{
		cout << "输入的月份应该在1-12之间" << endl;
	}
	else
	{
		if (month==4||month==6||month==9||month==11)
		{
			cout << "这个月有30天" << endl;
		}
		else if (month==2)
		{
			if (year%4==0&&year%100!=0||year%400==0)
			{
				cout << "这个月有29天" << endl;
			}
			else
			{
				cout << "这个月有28天" << endl;
			}
		}
		else
		{
			cout << "这个月有31天" << endl;
		}
	}

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐