C语言问题,求大神解决,谢谢啦,我是小白,最好能够解释下原因

2024-12-26 04:33:22
推荐回答(1个)
回答1:

#include
void main()
{
int year,day=0,y,n,day1=0,day2,length;
int mon1[12]={31,29,31,30,31,30,31,31,30,31,30,31};
int mon2[12]={31,28,31,30,31,30,31,31,30,31,30,31};
printf("请输入年份");
scanf("%d",&year);
for(y=1900;y {
if((y%400==0)||(y%4==0&&y%100!=0))
day=day+366;
else
day=day+365;
}
day=(day+1)%7;
printf("%d年的第一天是星期%d\n",year,day);
for(n=1;n<=12;n++)
{ day2=(day+day1)%7;
if(y%400==0||y%4==0&&y%100!=0)
day1=day1+mon1[n-1];
else
day1=day1+mon2[n-1];

printf("%d年的第%d月第一天是星期%d\n",year,n,day2);
day2=day2%7+1;
int k=1;
if(year%400==0||year%4==0&&year%100!=0)
{
length=mon1[n-1];
}
else
{
length=mon2[n-1];
}
printf("\n日\t一\t二\t三\t四\t五\t六\n");
for(int i=1;i {

if(i {
printf(" \t");
}
else
{
printf("%d\t",k);
k++;
}
if(i%7==0||k>length)
printf("\n");
}
printf("\n");
}

}