参考 https://www.nowcoder.com/profile/365362210/codeBookDetail?submissionId=118703040
闰年:四年一闰,百年不闰,四百年再闰
代码
#include <stdio.h>
int isleapyear(int year)
{
if(0 == year%4)
{
if(0 == year%100 && 0 != year%400)
return 0;
else
return 1;
}
else
return 0;
}
int main()
{
int daynum_of_leapyear[12] = {31,29,31,30,31,30,31,31,30,31,30,31};
int daynum_of_commonyear[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
int year,month,day;
scanf("%d %d %d", &year, &month, &day);
int daynum = 0;
if(1 == isleapyear(year))
{
for(int i =0; i<month-1; i++)
{
daynum += daynum_of_leapyear[i];
}
}
else
{
for(int i =0; i<month-1; i++)
{
daynum += daynum_of_commonyear[i];
}
}
daynum += day;
printf("%d",daynum);
return 0;
}