前段时间写的,部分有注释,你参考参考,不懂的问我./* * * * Createdon:2013-3-11 * Author:jw */#include<>#include<>//三维数组存放日期,每年12月,日历中最多排6行(星期),每星期7天intdays[12][6][7];//平年,闰年每个月的天数intds[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},{31,29, 31,30,31,30,31,31,30,31,30,31}};//标题chartitle[]="SUMMONTUEWEDTHUFRISAT";//月份intm[4][3]={{1,2,3},{4,5,6},{7,8,9},{10,11,12}};//月份charmt[][4]={"JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"};//根据蔡勒公式计算日期星期几intwd(intyear,intm,intd){ intc,y,w; if(m<=2){ year--; m+=12; } c=year/100; y=year%100; w=(c/4-2*c+y+y/4+13*(m+1)/5+d-1); return(w%7+7)%7;}//闰年平年intleapYear(intyear){ return(year%4==0&&year%100!=0)||(year%400==0);}intmain(){ inti,j,k,leap,fd,year; scanf("%d%*c",&year); //初始三维数组为0 for(i=0;i<12;i++){ for(j=0;j<6;j++){ for(k=0;k<7;k++){ days[i][j][k]=0; } } } fd=wd(year,1,1); leap=leapYear(year); //三维数组赋值 for(i=0;i<12;i++){ for(k=0,j=1;j<=ds[leap][i];j++){ days[i][k][fd]=j; fd=(++fd)%7; if(fd==0){ k++; } } } //输出数据 for(i=0;i<4;i++){ printf("%13s %27s %27s\n",mt[m[i][0]-1],mt[m[i][1]-1], mt[m[i][2]-1]); printf("%s %s %s\n",title,title,title); for(j=0;j<6;j++){ //1,4,7 for(k=0;k<7;k++){ if(days[m[i][0]-1][j][k]) printf("%4d",days[m[i][0]-1][j][k]); else printf(" "); } printf(" "); //2,5,8 for(k=0;k<7;k++){ if(days[m[i][1]-1][j][k]) printf("%4d",days[m[i][1]-1][j][k]); else printf(" "); } printf(" "); //3,6,9 for(k=0;k<7;k++){ if(days[m[i][2]-1][j][k]) printf("%4d",days[m[i][2]-1][j][k]); else printf(" "); } printf("\n"); } } return0;}-------------------------------------------------打印结果--------------------------------------------------------------------