#i nclude"stdio.h" void weekday(FILE *); int leap(int); int _2000yera(int x) { int sum=0; int i; if(x>=2000){ for(i=2000;i<x;i++) { sum+=(i%4==0&&i%100==0||i%400==0)?366:365; } return (sum+6)%7; } else{ for(i=x;i<2000;i++) { sum+=(i%4==0&&i%100==0||i%400==0)?366:365; } return (-sum%7+6)%7; }
} void weekday(FILE *fp) { int i; for(i=1;i<=7;i++) fprintf(fp,"星期%d\t",i); fputs("\n",fp); } int sp(int x,FILE *fp) { int i; for(i=1;i<=_2000yera(x);i++) fputs("\t",fp); return i; } int month(int ch,int x) { switch(ch) { case 1: case 3: case 5: case 7: case 8: case 10: case 12:return 31; case 4: case 6: case 9: case 11:return 30; case 2:return leap(x); } } int leap(int x) { return ((x%4==0&&x%100!=0)||x%400==0)?29:28; } int printyear(int x,FILE *fp) { int mon,i=1,j,day; fputs("*********1月*********",fp); fputs("\n",fp); weekday(fp); fputs("\n",fp); i=sp(x,fp); for(day=1,mon=1;mon<=12;mon++) { for(j=1;j<=month(mon,x);j++,i++,day++) { fprintf(fp,"%d\t",j); if(i%7==0){fputs("\n",fp);day=1;} } if(mon<12){ fputs("\n",fp); fprintf(fp,"*********%d月*********\n",mon+1); weekday(fp); fputs("\n",fp); i=1; i+=day-2; for(;day-2>0;day--) fputs(" \t",fp);} } } main() { FILE *fp; int x,exit; if((fp=fopen("d:\\en.txt","a+"))==NULL) { puts("不能打开此文件"); return 0; } printf("year:"); scanf("%d",&x); printyear(x,fp); rewind(fp); printf(
|