输入年份和月份,计算这一年这个月有多少天
#include<stdio.h>
int getDaysInMonth(int year, int month)
{
int arr[] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
int day = arr[month-1];
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
{
if(month==2)
{
day += 1;
}
}
return day;
}
int main()
{
int year = 0;
int month = 0;
printf("请输入年份与月份");
scanf("%d %d", &year, &month);
int days = getDaysInMonth(year, month);
printf("%d年%d月有%d天",year,month,days );
return 0;
}
如果对你有帮助的话就请点个赞吧