判断某年某月有多少天(嵌套调用)

#include
int is_leap_year(int x)
{
	if ((x % 4 == 0 && x % 100 != 0) || (x % 400 == 0))  //判断是否为闰年
		return 1;   //是则为真
	else
		return 0;   //否则为假
}

int get_days_of_month(int y, int m)
{
	int days[] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };  //用0来将下标0占用掉,好让下标对应月份
	int day = days[m];
	if (is_leap_year(y) && m == 2)  //是闰年且二月
		day += 1;  //+1天为29天
	return day;
}
int main()
{
	int year = 0;
	int month = 0;
	scanf("%d%d", &year, &month);
	int days = get_days_of_month(year, month);
	printf("%d\n", days);
	return 0;
}

你可能感兴趣的:(c语言)