输入日期计算天数

#include <stdio.h>
void main()
{
int year,month,day,daynum;
printf("请输入年月日,用,号隔开,格式列(2014,5,12)\n");
scanf("%d,%d,%d",&year,&month,&day);
switch(month)
{
case 1:
daynum=day;
break;
case 2:
daynum=30+day;
break;
case 3:
daynum=28+30+day;
break;
case 4:
daynum=31+28+30+day;
break;
case 5:
daynum=30+31+28+30+day;
break;
case 6:
daynum=31+30+31+28+30+day;
break;
case 7:
daynum=30+31+30+31+28+30+day;
break;
case 8:
daynum=31+30+31+30+31+28+30+day;
break;
case 9:
daynum=31+31+30+31+30+31+28+30+day;
break;
case 10:
daynum=30+31+31+30+31+30+31+28+30+day;
break;
case 11:
daynum=31+30+31+31+30+31+30+31+28+30+day;
break;
case 12:
daynum=30+31+30+31+31+30+31+30+31+28+30+day;
break;
}
if (year%4==0&&year%100!=0||year%400==0 )
{
daynum=daynum+1;
}
printf("该日期是当年的第%d天\n",daynum);
}

你可能感兴趣的:(日期)