万年历查询程序(c++) 1给定的日期显示该日是星期几 2输入的月份以日历形式显示本月各日对应星期

2024-11-25 13:03:08
推荐回答(1个)
回答1:

有个原来写的打印月份:都是比较普通的语句

#include
using namespace std;
int main()
{
int y,m,w,j;
int zeller(int year,int month,int day=1);
void print(int year,int month,int week,int j);
cout<<"输入年月:";
cin>>y>>m;
if (y%4==0&&y%100!=0||y%400==0&&m==2)
j=29;
else if (!(y%4==0&&y%100!=0||y%400==0)&&m==2)
j=28;
else if (m==1||m==3||m==5||m==7||m==8||m==10||m==12)
j=31;
else if (m==4||m==6||m==9||m==11)
j=30;
w=zeller(y,m);
print(y,m,w,j);
return 0;
}
int zeller(int year,int month,int day)
{
int cen,week,w,i;
if(month==1||month==2)
{
month+=12;
year-=1;
}
cen=year/100;
year=year%100;
w=year+year/4+cen/4-2*cen+int(13*(month+1)/5)+day-1;
while(w<0)
w=w+7;
week=w%7;
return week;
}
void print(int year,int month,int week,int j)
{
int i,a,b,c;
cout<<"星期日 星期一 星期二 星期三 星期四 星期五 星期六"< for (i=1;i<=week;i++)
cout<<'\t';
for (a=1;a<8;a++)
{
cout<<" "< if(a==7-week)
{
cout< break;
}
}
b=a+1;
for (c=1;b<=j;b++)
{
cout<<" "< if(c%7==0)
cout< c++;
}
}