#include <stdio.h>
int GetYearDay(int year, int month, int day);
int IsLeap(int year);
int main()
{
int year, month, day;
scanf("%d%d%d", &year, &month, &day);
printf("%d", GetYearDay(year, month, day));
}
int GetYearDay(int year, int month, int day)
{
int k, leap;
int tab[2][13] = {{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
{0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};
leap = IsLeap(year);
for (k = 0; k < month; k++)
{
day += tab[leap][k];
/* code */
}
return day;
}
int IsLeap(int year)
{
return ((year % 4 == 0 && year % 100 != 0 || year % 400 == 0));
}
《c语言程序设计》习题.日期计算
最新推荐文章于 2021-05-18 00:28:03 发布