#include <math.h>
#include <stdio.h>
void main()
{
int year,month,day,temp,M;
printf("输入某年某月某日:");
scanf("%d.%d.%d",&year,&month,&day);
if((year/4==0)&&(year/100!=0))
{
temp = 29;
}
else
{
temp = 28;
}
switch(month)
{
case 1:
{
if(day>0&&day<=31)
{
M = day;
printf("%d年%d月%d日是这一年中的第%d天",year,month,day,M);break;
}
else
{
printf("error\n");break;
}
}
case 2:
{
if(day>0&&day<=temp)
{
M = day+31;
printf("%d年%d月%d日是这一年中的第%d天",year,month,day,M);break;
}
else
{
printf("error\n");break;
}
}
case 3:
{
if(day>0&&day<=31)
{
M = day+31+temp;
printf("%d年%d月%d日是这一年中的第%d天",year,month,day,M);break;
}
else
{
printf("error\n");break;
}
}
case 4:
{
if(day>0&&day<=30)
{
M = day+31+temp+31;
printf("%d年%d月%d日是这一年中的第%d天",year,month,day,M);break;
}
else
{
printf("error\n");break;
}
}
case 5:
{
if(day>0&&day<=31)
{
M = day+31+temp+31+30;
printf("%d年%d月%d日是这一年中的第%d天",year,month,day,M);break;
}
else
{
printf("error\n");break;
}
}
case 6:
{
if(day>0&&day<=30)
{
M = day+31+temp+31+30+31;
printf("%d年%d月%d日是这一年中的第%d天",year,month,day,M);break;
}
else
{
printf("error\n");break;
}
}
case 7:
{
if(day>0&&day<=31)
{
M = day+31+temp+31+30+31+30;
printf("%d年%d月%d日是这一年中的第%d天",year,month,day,M);break;
}
else
{
printf("error\n");break;
}
}
case 8:
{
if(day>0&&day<=31)
{
M = day+31+temp+31+30+31+30+31;
printf("%d年%d月%d日是这一年中的第%d天",year,month,day,M);break;
}
else
{
printf("error\n");break;
}
}
case 9:
{
if(day>0&&day<=30)
{
M = day+31+temp+31+30+31+30+31+31;
printf("%d年%d月%d日是这一年中的第%d天",year,month,day,M);break;
}
else
{
printf("error\n");break;
}
}
case 10:
{
if(day>0&&day<=31)
{
M = day+31+temp+31+30+31+30+31+31+30;
printf("%d年%d月%d日是这一年中的第%d天",year,month,day,M);break;
}
else
{
printf("error\n");break;
}
}
case 11:
{
if(day>0&&day<=30)
{
M = day+31+temp+31+30+31+30+31+31+30+31;
printf("%d年%d月%d日是这一年中的第%d天",year,month,day,M);break;
}
else
{
printf("error\n");break;
}
}
case 12:
{
if(day>0&&day<=31)
{
M = day+31+temp+31+30+31+30+31+31+30+31+30;
printf("%d年%d月%d日是这一年中的第%d天",year,month,day,M);break;
}
else
{
printf("error\n");break;
}
}
default :
{
printf("error\n");break;
}
}
}
这是一个计算某一天是这一年中的天数的程序,现在的问题是:无法区分闰年还是平年。