那位大神能给注释下这个程序?感激不尽。
#include"stdio.h"#include"conio.h"
#include"stdlib.h"
int date[12][6][7];
int day_tbl[][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}};
long int f(int year,int month)
{
if(month<3)
return year-1;
else
return year;
}
long int g(int month)
{
if(month<3)
return month+13;
else
return month+1;
}
long int n(int year,int month,int day)
{
return 1461L*f(year,month)/4+153L*g(month)/5+day;
}
int w(int year,int month,int day)
{
return (int)((n(year,month,day)%7-621049L%7+7)%7);
}
int main(void)
{
int sw,leap,i,j,k,wd,day;
int year;
char c;
char title[]="SUN MON TUE WED THU FRI SAT";
system("title 万年历");
again:
printf("Please input the year whose calendar you want to know: ");
scanf("%d%*c",&year);
if(year>=1000&&year<=9999)
{
;}
else
{
system("cls");
puts("You have input a wrong number,press any key to input again...");
getch();
system("cls");
goto again;
}
sw=w(year,1,1);
leap=year%4==0&&year%100!=0||year%400==0;
for(i=0;i<12;i++)
for(j=0;j<6;j++)
for(k=0;k<7;k++)
date[i][j][k]=0;
for(i=0;i<12;i++)
{
for(wd=0,day=1;day<=day_tbl[leap][i];day++)
{
date[i][wd][sw]=day;
sw=++sw%7;
if(sw==0)
wd++;
}
}
printf("\n|===================The Calendar of Year %d =====================|\n|",year);
for(i=0;i<6;i++)
{
for(wd=0,k=0;k<7;k++)
wd+=date[i][5][k]+date[i+6][5][k];
wd=wd?6:5;
printf("%2d %s %2d %s |\n|",i+1,title ,i+7,title);
for(j=0;j<wd;j++)
{
printf(" ");/*输出3个空白符*/
for(k=0;k<7;k++)
{
if (date[i][j][k])
printf("%4d",date[i][j][k]);
else
printf(" ");/*输出4个空白符*/
}
printf(" ");/*输出6个空白符*/
for(k=0;k<7;k++)
{
if(date[i+6][j][k])
printf("%4d",date[i+6][j][k]);
else
printf(" ");/*输出4个空白符*/
}
printf(" |\n|");
}
}
printf("===================%s ================|");
puts("\n\n Press any key to continue,'n' or 'N' to quit...");
c=getch();
if(c=='n'||c=='N')
{
printf("\n\n");
goto over;
}
else
{
system("cls");
goto again;
}
over:
return 0;
}
[ 本帖最后由 千雨陌 于 2013-7-23 09:17 编辑 ]