判断平年还是闰年是这一年第多少天[宝典]
#include
void main()
{
int year,i,mouth,days,s=0;
printf("本日历只适用于2012年,你也可以做修改。\n");
printf("Please you enter year:\n");
printf("Year=");
scanf("%d",&year);
if(year%400==0)
{ i=1;
printf("This is a not leap year.\n");
if(i==1)
printf("please you enter mouth and days:\n");
printf("Mouth=");
scanf("%d",&mouth);
printf("Days=");
scanf("%d",&days);
switch(mouth)
{
case 1:s=0+days;
printf("This is %d days of %d mouth in the %d year.\n",s,mouth,year);
break;
case 2:s=31+days;
printf("This is %d days of %d mouth in the %d year.\n",s,mouth,year);
break;
case 3:s=60+days;
printf("This is %d days of %d mouth in the %d year.\n",s,mouth,year);
break;
case 4:s=91+days;
printf("This is %d days of %d mouth in the %d year.\n",s,mouth,year);
break;
case 5:s=121+days;
printf("This is %d days of %d mouth in the %d year.\n",s,mouth,year);
break;
case 6:s=152+days;
printf("This is %d days of %d mouth in the %d year.\n",s,mouth,year);
break;
case 7:s=182+days;
printf("This is %d days of %d mouth in the %d year.\n",s,mouth,year);
break;
case 8:s=213+days;
printf("This is %d days of %d mouth in the %d year.\n",s,mouth,year);
break;
case 9:s=244+days;
printf("This is %d days of %d mouth in the %d year.\n",s,mouth,year);
break;
case 10:s=274+days;
printf("This is %d days of %d mouth in the %d year.\n",s,mouth,year);
break;
case 11:s=305+days;
printf("This is %d days of %d mouth in the %d year.\n",s,mouth,year);
break;
case 12:s=335+days;
printf("This is %d days of %d mouth in the %d year.\n",s,mouth,year);
break;
default:
printf("error\n");
}
if(i==1)
s=(s+7-1)%7;
switch(s)
{
case 0:printf("This is Sunday.\n");
break;
case 1:printf("This is Monday.\n");
break;
case 2:printf("This is Tuesday.\n");
break;
case 3:printf("This is Wednesday.\n");
break;
case 4:printf("This is Thursday.\n");
break;
case 5:printf("This is Friday.\n");
break;
case 6:printf("This is Saturday.\n");
break;
}
}
else
i=0;
if(i==0)
{ printf("This is a leap year.\n");
printf("please you enter mouth and days:\n");
printf("Mouth=");
scanf("%d",&mouth);
printf("Days=");
scanf("%d",&days); switch(mouth)
{
case 1:s=0+days;
printf("This is %d days of %d mouth in the %d year.\n",s,mouth,year);
break;
case 2:s=31+days;
printf("This is %d days of %d mouth in the %d year.\n",s,mouth,year);
break;
case 3:s=59+days;
printf("This is %d days of %d mouth in the %d year.\n",s,mouth,year);
break;
case 4:s=90+days;
printf("This is %d days of %d mouth in the %d year.\n",s,mouth,year);
break;
case 5:s=120+days;
printf("This is %d days of %d mouth in the %d year.\n",s,mouth,year);
break;
case 6:s=151+days;
printf("This is %d days of %d mouth in the %d year.\n",s,mouth,year);
break;
case 7:s=181+days;
printf("This is %d days of %d mouth in the %d year.\n",s,mouth,year);
break;
case 8:s=212+days;
printf("This is %d days of %d mouth in the %d year.\n",s,mouth,year);
break;
case 9:s=243+days;
printf("This is %d days of %d mouth in the %d year.\n",s,mouth,year);
break;
case 10:s=273+days;
printf("This is %d days of %d mouth in the %d year.\n",s,mouth,year);
break;
case 11:s=304+days;
printf("This is %d days of %d mouth in the %d year.\n",s,mouth,year);
break;
case 12:s=334+days;
printf("This is %d days of %d mouth in the %d year.\n",s,mouth,year);
break;
default:
printf("error\n");
}
}
if(i==0)
s=(s+7)%7;
switch(s)
{
case 0:printf("This is Sunday.\n");
break;
case 1:printf("This is Monday.\n");
break;
case 2:printf("This is Tuesday.\n");
break;
case 3:printf("This is Wednesday.\n");
break;
case 4:printf("This is Thursday.\n");
break;
case 5:printf("This is Friday.\n");
break;
case 6:printf("This is Saturday.\n");
break;
}