
1个回答
展开全部
自己写的,运行无措,参考下吧~
#include <stdio.h>
main()
{
int y,m,d,n=0,i=0;
int m1[]={31,28,31,30,31,30,31,31,30,31,30,31};
int m2[]={31,29,31,30,31,30,31,31,30,31,30,31};
printf("please input the date(YYYY-MM-DD):\n");
scanf("%d-%d-%d",&y,&m,&d);
if(y%4!=0&&y%400!=0) //平年判断
{ if(d>m1[m-1])
{printf("ERROR! No %dth in %d,%d.\n",d,m,y);
}
else{
while(i<m-1)
{n=n+m1[i];
i++;}
n=n+d;
printf("%d-%d-%d is the %dth day of the year %d\n",y,m,d,n,y);
}
}
else{
if(d>m2[m-1])
{printf("ERROR! No %dth in %d,%d.\n",d,m,y);
}
else{
while(i<m-1)
{n=n+m2[i];
i++;
}
n=n+d;
printf("%d-%d-%d is the %dth day of the year %d\n",y,m,d,n,y);
}
}
}
#include <stdio.h>
main()
{
int y,m,d,n=0,i=0;
int m1[]={31,28,31,30,31,30,31,31,30,31,30,31};
int m2[]={31,29,31,30,31,30,31,31,30,31,30,31};
printf("please input the date(YYYY-MM-DD):\n");
scanf("%d-%d-%d",&y,&m,&d);
if(y%4!=0&&y%400!=0) //平年判断
{ if(d>m1[m-1])
{printf("ERROR! No %dth in %d,%d.\n",d,m,y);
}
else{
while(i<m-1)
{n=n+m1[i];
i++;}
n=n+d;
printf("%d-%d-%d is the %dth day of the year %d\n",y,m,d,n,y);
}
}
else{
if(d>m2[m-1])
{printf("ERROR! No %dth in %d,%d.\n",d,m,y);
}
else{
while(i<m-1)
{n=n+m2[i];
i++;
}
n=n+d;
printf("%d-%d-%d is the %dth day of the year %d\n",y,m,d,n,y);
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询