输入一个年份和一个月份,输出该年该月有多少天

时间:2025-02-10 08:30:10

开发环境为Dev C++

思路:

1、先定义好年、月

2、判断年份是否为闰年

3、不同月份的天数为多少

代码如下:

#include<>
int main(void)
{
	int year,month;
	printf("input year:");
	scanf("%d",&year);
	printf("input month:");
	scanf("%d",&month);
	switch(month)
	{
		case 1:
		case 3:
	    case 5:
		case 7:
		case 8:
		case 10:
		case 12:
			{
			printf("The number of days in the month is 31 days.");
			break;
			}
		case 4:
		case 6:
		case 9:
		case 11:
			{
			printf("The number of days in the month is 30 days.");
			break;
			}
		case 2:
			if(year%4==0&&year%100!=0||year%400==0)     //判断是否为闰年
				printf("The number of days in the month is 29 days.");
			else
			    printf("The number of days in the month is 28 days.");
		default:
		    printf("Not this month");					
	}
	return 0;
}