【C++】输入年号和月份,输出这一年的该月的天数。(提示:要先判断输入年份是否为闰年

#include
int t10()
{
	int day, month, year;
	printf("请输入年号和月份:");
	scanf("%d %d", &year, &month);
	if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))
	{
		switch (month)
		{
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12:
			day = 31;
			break;
		case 2:
			day = 29;
			break;
		case 4:
		case 6:
		case 9:
		case 11:
			day = 30;
			break;
		}
	}
	else
	{
		switch (month)
		{
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12:
			day = 31;
			break;
		case 2:
			day =28;
			break;
		case 4:
		case 6:
		case 9:
		case 11:
			day = 30;
			break;
		}
	}
	printf("%d", day);
	return 0;
}
int main()
{
t10();
return 0;
}

你可能感兴趣的:(c++,算法,数据结构)