自定义1个函数day_of_year(year, month, day),计算并返回年year、月month和日day对应的是该年的第几天。
函数接口定义:
int day_of_year(year, month, day);
year, month, day分别为输入的年,月,日
裁判测试程序样例:
#include<stdio.h>
int day_of_year(int year, int month, int day);
int main(void)
{
int year,month,day;
scanf("%d%d%d",&year,&month,&day);
printf("%d",day_of_year(year,month,day));
return 0;
}
/* 请在这里填写答案 */
输入样例:
2000 3 1
输出样例:
61
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB
C程序如下:
int day_of_year(year, month, day)
{int a[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };int sum = 0;if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0){for (int i = 1; i < month; i++){sum += a[i];}sum += day + 1;}else{for (int i = 1; i < month; i++){sum += a[i];}sum += day;}return sum;
}