日历显示:输入任一年将显示出该年的所有月份日期,对应的星期 用C语言编程

2024-11-25 20:55:40
推荐回答(1个)
回答1:

#include
int main()
{
inti=0,m=0,k=1,leap=1973,year,f=0,week,r,p=2,g=2,flag;
int a[12]={31,28,31,30,31,30,31,31,30,31,30,31};//月份终止
int b[12]={0,3,3,6,1,4,6,2,5,0,3,5};//控制周换行1973初始值
int c[12]={};
void space(int);
printf("请输入年份(1973年以后):\n");
scanf("%d",&year);
while(leap{
leap=leap+1;
if(leap%4==0&&leap%100!=0)flag=0;
elseif(leap%400==0&&leap%100==0)flag=0;
else {flag=1;f++;}
}
r=year-1973-f;
printf("\n");
if(flag==1){c[0]=(b[0]+2*r+f)%7;c[1]=(b[1]+2*r+f)%7;}
if(flag==0){(c[0]=(b[0]+2*(r-1)+f)%7+1)%7;c[1]=((b[1]+2*(r-1)+f)%7+1)%7;}
while(g<12)
{
c[p]=(b[g]+2*r+f)%7;
p++;g++;
}
if(year%4==0&&year%100!=0)a[1]=29;
elseif(year%400==0&&year%100==0)a[1]=29;
else a[1]=28;
while(k<13)
{
space(10);
printf("%d月\n",k);
printf("一二三四五六日\n");
space(3*c[m]+1);//周前空格与周换行正比
while(i{
i++;
if(i<10)printf("%d",i);
if(i>=10)printf("%d ",i);
if((i+c[m])%7==0)printf("\n");
}
m++;
i=0;
k++;
printf("\n");
}
getchar();
getchar();
}
void space(int x)
{
int i;
for(i=1;i}