C语言 万年历计算星期几的问题

2025-03-01 08:37:43
推荐回答(3个)
回答1:

day-1表示这个月的日到1日引起的星期差。+6是因为2000年1月1日是星期六。

回答2:

#include
#include
#include

int main()
{
int c,i,x,s,num,year,month,day,j=1,k=1;
//SYSTEMTIME sysT;
//GetSystemTime(&sysT);
//year=sysT.wYear;
//month=sysT.wMonth;
cout<<"input year and month:"< cin>>year>>month;
{
if(((year%4==0)&&(year%100!=0))||(year%400==0)) x=29;
else x=28;
if (month==1) c=1;
else if (month==2) c=31+1;
else if (month==3) c=31+x+1;
else if (month==4) c=31+31+x+1;
else if (month==5) c=31+31+30+x+1;
else if (month==6) c=31+31+30+31+x+1;
else if (month==7) c=31+31+30+31+30+x+1;
else if (month==8) c=31+31+30+31+30+31+x+1;
else if (month==9) c=31+31+30+31+30+31+31+x+1;
else if (month==10) c=31+31+30+31+30+31+31+30+x+1;
else if (month==11) c=31+31+30+31+30+31+31+30+31+x+1;
else if (month==12) c=31+31+30+31+30+31+31+30+31+30+x+1;
}
s=year-1+(year-1)/4-(year-1)/100+(year-1)/400+c;
num=s%7;
{
if (month==1||month==3||month==5||month==7||month==8||month==10||month==12) day=31;
else if (month==4||month==6||month==9||month==11) day=30;
else if (month=2&&(((year%4==0)&&(year%100!=0))||(year%400==0))) day=29;
else day=28;
}
cout<<"日"<<'\t'<<"一"<<'\t'<<"二"<<'\t'<<"三"<<'\t'<<"四"<<'\t'<<"五"<<'\t'<<"六"<<'\t'< if(num==7)
{
for (i=1;i<=day;i++)
{
cout< }
}
if(num!=7)
{
while(j<=num)
{
cout<<"\t";
j++;
}
for (i=1;i<=day;i++)
{
cout< if (i==7*k-num)
{
cout< k++;
}
}
}
cout< return 0;
}

如果只是想要代码的话,这儿有:

这样就可以了哈,亲。把注释那儿去掉就自动读取系统当前的年月进行显示

回答3:

2000年1月1日 星期六

365/7 = 52..........1