一年的第几天
#include <stdio.h>struct DATE
{ int year;
int month;
int day;
};
int days(struct DATE date)
{ int s;int w=0;
if(date.year%4==0)
{w=1;
if(date.year%100==0&&date.year%400!=0)
w=0;}
if(w==1)
{switch(date.month)
{case 1:s=date.day;break;
case 2:s=date.day+31;break;
case 3:s=date.day+60;break;
case 4:s=date.day+91;break;
case 5:s=date.day+121;break;
case 6:s=date.day+152;break;
case 7:s=date.day+182;break;
case 8:s=date.day+213;break;
case 9:s=date.day+244;break;
case 10:s=date.day+274;break;
case 11:s=date.day+305;break;
case 12:s=date.day+335;break;
return s;
}
}
else
{switch(date.month)
{case 1:s=date.day;break;
case 2:s=date.day+31;break;
case 3:s=date.day+59;break;
case 4:s=date.day+90;break;
case 5:s=date.day+120;break;
case 6:s=date.day+151;break;
case 7:s=date.day+181;break;
case 8:s=date.day+212;break;
case 9:s=date.day+243;break;
case 10:s=date.day+273;break;
case 11:s=date.day+304;break;
case 12:s=date.day+334;break;
return s;
}
}
}
int main()
{
struct DATE d;
scanf("%d-%d-%d", &d.year, &d.month, &d.day);
printf("%d", days(d));
}
[此贴子已经被作者于2017-11-12 13:01编辑过]