求助万年历问题
#include <stdio.h>
int CaculateWeekDay(int year,int month,int day)
{
int week;
if(month==1||month==2)
{
month+=12;
year--;
}
week=(day+2*month+3*(month+1)/5+year+year/4-year/100+year/400)%7+day;
return week;
}
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}};
main()
{
int FirstDay,i,j,k,wd=0,day,leap;
int Year;
char title[]="SUN MON TUE WED THU FRI SAT";
printf("Please input the year whose calendar you want to know: ");
scanf("%d",&Year);
FirstDay=CaculateWeekDay(Year,1,1);
leap = (Year % 4 == 0) && (Year % 100) || (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++)
{
wd = 0;
for(day=1;day <= day_tbl[leap][i];day++)
{
date[i][wd][FirstDay] = day;
FirstDay = ++FirstDay % 7;
if(FirstDay == 0)
wd++;
}
}
for(i=0;i<12;i++)
{
for(k=0,wd=0;k<7;k++)
wd+=date[i][5][k];
wd = wd ? 6 : 5;
printf(" %s\n",title);
for(j=0;j<wd;j++)
{
for(k=0;k<7;k++)
if(date[i][j][k])
printf("%4d",date[i][j][k]);
else printf(" ");
printf("\n");
}
}
puts("\n press any key to quit....");
getchar();
}
这是我编写的万年历 输出时是一次输出一年 需要改成一次输出一排(两个月为一排) 按回车后再显示下一排 直到显示完12个月
如: 1月 2月
3月 4月
应该是在第六排修改 求解~~~