示例代码3
这段代码封装了两个函数分别处理,整⽉整年地统计今天到⽣⽇的间隔。效率更⾼。
case 4:
case 6:
case 9:
case 11:
return 30;
case 2:
if (isLeapYear(y))
return 29;
else
return 28;
default:
return 0;
}
}
int getNextLeapYear(int y)
{
while (!isLeapYear(y))
{
y++;
}
return y;
}
//计算1999年1⽉1⽇到y、m、d多少天
int getDays(int y, int m, int d)
{
int i, count = 0;
for (i = 1999; i < y; i++)
{
count += 365;
if (isLeapYear(i))
count++;
}
for (i = 1; i < m; i++)
{
count += getMonthDays(y, i);
}
count += d;
return count;
}
#include <stdio.h>
#include <math.h>
#include <string.h>
int year1, mon1, day1, year2, mon2, day2, n1, n2, ans;