首页 > 代码库 > 判断一年中的第几天
判断一年中的第几天
#include <stdio.h>
void main()
{
int year,month,day,sum,m;
printf("请输入年月日(如:1991,1,1)\n");
scanf("%d,%d,%d",&year,&month,&day);
if((month==2&&day==30)||(month==2&&day==31))
{
printf("2月没有30或31天,请重新输入:");
scanf("%d,%d,%d",&year,&month,&day);
}
if((year%4==0&&year%100!=0)||(year%400==0))
{
m=29;
}
else
{
m=28;
}
switch(month)
{
case 1: sum=0;
break;
case 2: sum=31;
break;
case 3: sum=m+31;
break;
case 4: sum=m+31+31;
break;
case 5: sum=m+31+31+30;
break;
case 6: sum=m+31+31+30+31;
break;
case 7: sum=m+31+31+30+31+30;
break;
case 8: sum=m+31+31+30+31+30+31;
break;
case 9: sum=m+31+31+30+31+30+31+31;
break;
case 10: sum=m+31+31+30+31+30+31+31+30;
break;
case 11: sum=m+31+31+30+31+30+31+31+30+31;
break;
case 12: sum=m+31+31+30+31+30+31+31+30+31+30;
break;
}
sum=sum+day;
printf("%d,%d,%d是这年当中的第%d天\n",year,month,day,sum);
}