#include <stdio.h>
bool isLeapYear(int year)
{
if ((year%4==0&& year%100!=0) || year%400==0)
return true;
else return false;
}
int days_per_month(int year, int month)
{
switch(month)
{
case 1:return 31;
case 2: if (isLeapYear(year))return 29; else return 28;
case 3:return 31;
case 4:return 30;
case 5:return 31;
case 6:return 30;
case 7:return 31;
case 8:return 31;
case 9:return 30;
case 10:return 31;
case 11:return 30;
case 12:return 31;
default: return 0;
}
}
int days_per_year(int year)
{
if (isLeapYear(year)) return 366;
return 365;
}
void subOneDay(int &year,int &month, int &day)
{
day--;
if(day==0)
{
month--;
if(month==0){year--;month=12;}
day=days_per_month(year,month);
}
return;
}
int main()
{
int year,month,day;
int year_table[]={1949,1952,1966,1972,1983,1995,2003,2012};
printf("Input year,month,day:\n");
scanf("%d %d %d",&year,&month,&day);
for(int i=0;i<8;i++)
{
int temp_year=year,temp_month=month,temp_day=day,sum=0;
if (isLeapYear(year_table[i]))
{
while (1)
{
subOneDay(temp_year,temp_month,temp_day);
sum++;
if(temp_year==year_table[i]&&temp_month==10&&temp_day==1) break;
};
printf("%d年是闰年,今天离那年国庆节%d天:\n",year_table[i],sum);
}
else
{
while (1)
{
subOneDay(temp_year,temp_month,temp_day);
sum++;
if(temp_year==year_table[i]&&temp_month==6&&temp_day==1) break;
};
printf("%d年不是闰年,今天离那年儿童节%d天:\n",year_table[i],sum);
}
}
return 0;
}
本回答被网友采纳