记录一下自己写的小程序
#include <stdio.h>int main()
{
int year1, year2, month1, month2, day1,
day2;
printf("请输入较小的年月日;例如2020 1 6\n");
scanf("%d%d%d", &year1, &month1, &day1);
printf("请输入较大的年月日;例如2020 1 6\n");
scanf("%d%d%d", &year2, &month2, &day2);
int run[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int ping[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int i = 1, b = 1, zong1 = 0, zong2 = 0;
for (i = 1; i < year1; i++)
{
if (i % 400 == 0 || (i % 100 != 0 && i % 4 == 0))
{
zong1 += 366;
if ((i + 1) == year1)
{
for (b = 1; b < month1; b++)
zong1 += run[b];
}
}
else
{
zong1 += 365;
if ((i + 1) == year1)
{
for (b = 1; b < month1; b++)
zong1 += ping[b];
}
}
}
zong1 = zong1 + day1 - 1;
for (i = 1; i < year2; i++)
{
if (i % 400 == 0 || (i % 100 != 0 && i % 4 == 0))
{
zong2 += 366;
if ((i + 1) == year2)
{
for (b = 1; b < month2; b++)
zong2 += run[b];
}
}
else
{
zong2 += 365;
if ((i + 1) == year2)
{
for (b = 1; b < month2; b++) zong2 += ping[b];
}
}
}
zong2 = zong2 + day2 - 1;
printf("zong1=%d,zong2=%d\n", zong1, zong2);
printf("相差天数:%d", zong2 - zong1);
getchar();
}