有个原来写的打印月份:都是比较普通的语句
#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<<"星期日 星期一 星期二 星期三 星期四 星期五 星期六"<
cout<<'\t';
for (a=1;a<8;a++)
{
cout<<" "< if(a==7-week)
{
cout<
}
}
b=a+1;
for (c=1;b<=j;b++)
{
cout<<" "< if(c%7==0)
cout<
}
}