#include <stdio.h>
#include <time.h>
#include <stdlib.h>
void date_s(int *T_Y,int *T_M,int *T_D);
void runnian(int *,int y);
int loop(int *array,int y,int m,int d,int nd);
int main(void)
{
int array[12]={31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int nd=20000;//相差天数
int year=0,month=0,day=0;
date_s(&year,&month,&day);
printf("%4d/%02d/%02d\n",year,month+1,day);
loop(array,year,month,day,nd);
return 0;
}
//计算当前日期
void date_s(int *year,int *month,int *day)
{
time_t t;
time(&t);
struct tm *p = localtime(&t);
*year=p->tm_year+1900;
*month=p->tm_mon;
*day=p->tm_mday;
}
//计算闰年
void runnian(int *array,int y)
{
if ( y%4 == 0 && y%100 != 0) array[1]=(29);
else if (! (y%400)) array[1]=(29);
else array[1]=(28);
}
//循环天数
int loop(int *array,int y,int m,int d,int nd)
{
runnian(array,y);
int i=1;
for (;i<=nd;i++)
{
if (i < d)
{
printf("%4d/%02d/%02d\n",y,m+1,d-i);
continue;
}
else
{
m--;nd-=d;i=-1;
if (m < 0)
{
m=11;y--;
runnian(array,y);
}
d=array[m];
}
}
}