本帖最后由 Gin_Q 于 2020-3-9 19:13 编辑
附一个C的- #if 0
- By Gin
- Dec-C++ 5.11
- xx.c
- #endif
- #include <stdio.h>
- #include <time.h>
- #include <stdlib.h>
-
- void date_s(int *year,int *month,int *day);
- void runnian(int *,int y);
- void 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);
- }
- //循环天数
- void 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];
- }
- }
- }
复制代码
- 1965/06/12
- 1965/06/11
- 1965/06/10
- 1965/06/09
- 1965/06/08
- 1965/06/07
- 1965/06/06
-
- --------------------------------
- Process exited after 0.8944 seconds with return value 0
- 请按任意键继续. . .
复制代码
|