描述
根据输入的日期,计算是这一年的第几天。
输入描述:
输入一行,每行空格分割,分别是年,月,日
输出描述:
输出是这一年的第几天
示例1
输入:
2012 12 31
复制
输出:
366
复制
示例2
输入:
1982 3 4
输出:
63
#include <stdio.h>
int a[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int b[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main(void)
{
int year, month, day;
int i;
int sum = 0;
scanf("%d", &year);
scanf("%d", &month);
scanf("%d", &day);
sum = day;
if(year%400==0 || (year%4==0&&year%100!=0))
{
for(i=0; i<month-1; i++)
{
sum = sum+b[i];
}
}
else
{
for(i=0; i<month-1; i++)
{
sum = sum+a[i];
}
}
printf("%d\n", sum);
}