题目描述
输入年份和月份,输出这一年的这一月有多少天。需要考虑闰年。
输入格式
输入两个正整数,分别表示年份 y和月数 m,以空格隔开。
输出格式
输出一行一个正整数,表示这个月有多少天。
代码部分
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int Leap_year(int year) //判断是否为闰年的函数
{
if (year % 4 == 0) //判断是否被4整除
{
if (year % 100 == 0) //判断是否被100整除
{
if (year % 400 == 0) //判断是否被400整除
{
return 1; //被400整除是闰年
}
else
{
return 0; //不被400整除不是闰年
}
}
else
{
return 1; //不被100整除是闰年
}
}
else //不被4整除则不是闰年
{
return 0;
}
}
int Month_day(int year,int month) //判断月份有几天的函数
{
if (month == 1)
{
return 31;
}
else if (month == 2)
{
if (Leap_year(year) == 0) //判断是不是闰年,不是闰年Leap_year(year)为0
{
return 28;
}
else //Leap_year(year)为1
{
return 29;
}
}
else if (month == 3)
{
return 31;
}
else if (month == 4)
{
return 30;
}
else if (month == 5)
{
return 31;
}
else if (month == 6)
{
return 30;
}
else if (month == 7)
{
return 31;
}
else if (month == 8)
{
return 31;
}
else if (month == 9)
{
return 30;
}
else if (month == 10)
{
return 31;
}
else if (month == 11)
{
return 30;
}
else
{
return 31;
}
}
int main()
{
int year, month;
scanf("%d %d", &year, &month);
printf("%d",Month_day(year, month));
return 0;
}