C语言编程题:定义1个函数day_of_year(year, month, day),计算一个日期对应的是该年的第几天。

2024-11-07 19:25:37
推荐回答(1个)
回答1:

int isLeapYear(int year)
{
return year%4==0&&year%100!=0||year%400=0;
}
int day_of_year(int year, int month, int day)
{
const int m[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int i,s=day;

for(i=0;is+=m[i];
if(isLeapYear(year))
s++;
return s;
}