学着别人写万年历,可总不成功,帮忙看看原因
今天看见个别人发的万年历程序,就研究好久,后来似有所得,便按照原来的思路也想写个万年历,几几经努力总是失败,证明自己还差的太远,可我实在想知道失败的原因,请大家帮看看,帮找找#include<stdio.h>
#include<stdlib.h>
char month_name[13][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"};
int month_day[12]={31,29,31,30,31,30,31,31,30,31,30,31};
int month2[6][7];
print1(month)
{
int t,i,j,p=0,m=1;
printf("===%s===\n",month_name[month]);
for(t=0;t<=6;t++)
printf("%7s",weekday_name[t]);
printf("\n");
for(i=0;i<6;i++)
for(j=0;j<7;j++)
{
printf("%7d",month2[i][j]);
p++;
if(p%7==0)
printf("\n");
}
}
leapyear(year)
{
if(year%4==0&&year%100!=0||year%400==0)
return(1);
else
return(0);
}
calendar(int year)
{
int month,weekday,x;
int i,j,t=0,k;
printf("*****%d*****",year);
weekday=(year+(year-1)/4-(year-1)/100+(year-1)/400)%7;
if(leapyear(year))
month_day[2]=29;
else
month_day[2]=28;
for(month=1;month<=12;month++)
{
scanf("%d",&x);
for(i=0;i<6;i++)
for(j=0;j<=6;j++)
month2[i][j]=0;
for(k=1;k<=month_day[month];k++)
{
month2[t][weekday]=k;
weekday++;
if(weekday=6)
{
weekday=0;
t++;
}
}
print1(month,k);
}
}
main()
{
int year;
printf("qing shu ru nian fen:\n");
scanf("%d",&year);
calendar( year);
getch();
}
另外小弟在程序中加的scanf("%d",&x);只是为了让程序停顿一下,便于便于排错,没有实际意义。
帮看看,稍稍占用点时间,谢谢。