當然,這個程序很簡單,呵呵,簡單也做了下
/*
計算輸入的時間是一年中的第幾天
*/
void theDayOfYear()
{
int nonleapYear[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
int leapYear[12] = {31,29,31,30,31,30,31,31,30,31,30,31};
int year,month,day,num=0;
printf("please input date like:2012 4 24 \n");
scanf("%d %d %d",&year,&month,&day);
//判斷是否是閏年
if((year%4==0&&year%100!=0)||year%400==0)
{
for(int i=0;i<month-1;i++)
{
num += leapYear[i];
}
num += day;
}
else
{
for(int i=0;i<month-1;i++)
{
num += nonleapYear[i];
}
num += day;
}
printf("the day of year is:%d\n",num);
}