#include<stdio.h>
#include<stdlib.h>
printk(int k);
main()
{
char month_name[12][9]={"January","February","March","April","May","June",
"July","August","September","October","November","December"};
char weekday_name[7][4]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"},a[6][7];
int month_day[2][13]={{0,31,28,31,30,31,30,31,31,30,31,30,31},
{0,31,29,31,30,31,30,31,31,30,31,30,31}};
do
{
int leap,year,month,day,FirstDay_Year,FirstDay_Month,i,j,num;
printf("input a year num:");
scanf("%5d",&year);
if(year==0)
exit(1);
printf("输入查询月份1--12:");
scanf("%3d",&month);
leap=year%4==0&&year%100!=0||year%400==0 ; //如果该语句为真,则为闰年,leap为1,否则为0
FirstDay_Year=5*(year/4)+(year%4)-(year/100)+(year/400);//0--6(0表示星期日)
for(i=1,day=0;i<month;i++)
day=day+month_name[leap][i];
FirstDay_Month=(day+FirstDay_Year)%7;
for(num=1,i=0,j=FirstDay_Month;num<=month_day[leap][month];num++)
{
a[i][j]=num;
if((j+1)%7==0)
i++;
j=(j+1)%7;
}
printf("THE Calendar of Year %d\n",year);
printf("%d\t",month);
printf(" SUN MON TUE WED THU FRI SAT");
for(num=1,printf("\n\t"),i=0,j=FirstDay_Month;num<=month_day[leap][month];num++)
{
if(num==1)
{
printk(j);
}
printf("%4d",a[i][j]);
if((j+1)%7==0)
{
i++;
printf("\n\t");
}
j=(j+1)%7;
}
printf("\n");
}while(1);
}
printk(int k)
{
int s;
for(s=0;s<4*k;s++)
printf(" ");
}
我的这个输出没问题,就是月与月之间的连接有问题,嘿嘿!