求解下万年历
求个高手教下 万年历月历第一个星期前面的空格要怎么弄 (注:因为我课本才看到了for 麻烦弄点我能看得懂的谢谢)
网上搜的 不知道是否准确 自己验证
#include<stdio.h>
#include<stdlib.h>
int monthday[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
/*数组monthday[13]存放每个月的天数*/
char monthname[13][6]={"","JAN","FEB","MAR","APR","MAY","JUNE",
"JULY","AUG","SEP","OCT","NOV","DEC"};
/*数组monthname[][]存放每个月的英文名称,用于打印*/
char weekday[8][6]={"SUN","MAN","TUE","WED","THU","FRI","SAT","SUM"};
/*数组weekday[][]存放一周的每一天的英文名称,用于打印*/
int month2[6][7];
int leapyear(int year)
/*函数1:判断year是否为闰年*/
{if((year%4==0)&&(year%100)!=0||(year%400)==0)
return 1;
else
return 0;
}
void print2(int month,int t)
/*函数2:按月打印日历*/
{ int i,j;
printf("*** %s ***\n",monthname[month]);
for(i=0;i<=6;i++)
printf("%5s",weekday[i]);
printf("\n");
for(i=0;i<=t;i++)
{for(j=0;j<=6;j++)
if(month2[i][j]==0)
printf(" ");
else
printf("%5d",month2[i][j]);
printf("\n");
}
}
void calendar(int year)
/*函数3:主体函数,按月生成日历*/
{int month;
int todayweek,today,i,j,t;
if(leapyear(year))
monthday[2]=29;
else
monthday[2]=28;
todayweek=year+(year-1)/4-(year-1)/100+(year-1)/400;
todayweek=todayweek%7;
/*计算当年第1天是星期几*/
printf("=== year %d ===\n",year);
for(month=1;month<=12;month++)
{today=1;
for(i=0;i<=5;i++)
for(j=0;j<=5;j++)
month2[i][j]=0;
t=0;
while(today<=monthday[month])
{month2[t][todayweek]=today;
todayweek++; today++;
if(todayweek==7)
{todayweek=0;
t++;
}
}
print2(month,t);
}
}
main()
{int year;
printf("请输入年份:\n");
scanf("%d",&year);
calendar(year);
system("pause");
}