//算元旦的星期 s=x-1+(x-1)/4-(x-1)/100+(x-1)/400+c x为年 c为从元旦起的总天数
#include "iostream.h"
#include "stdlib.h"
void print1(int y)
{
cout<<y<<"月"<<"\t\t"<<"日"<<"\t"<<"一"<<"\t"<<"二"<<"\t"<<"三"<<"\t"<<"四"<<"\t"<<"五"<<"\t"<<"六"<<endl;
}
int print2(int n,int c) //计算星期
{
int s;
s=n-1+(n-1)/4-(n-1)/100+(n-1)/400+c;
return(s%7);
}
int print3(int t,int n) //月
{
switch (t)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
return (31);
case 4:
case 6:
case 9:
case 11:
return(30);
case 2:
if(n%4==0&&n%100!=0||n%400==0)
{
return(29);
}
else
{
return(28);
}
}
}
void print4(int n)
{
int day,week;
week=print2(n,1);
for(int j=1;j<=12;j++)
{
day=print3(j,n);
print1(j);
cout<<"\t\t";
for(int k=1;k<=week;k++)
{
cout<<"\t";
}
for(int i=1;i<=day;i++)
{
cout<<i<<"\t";
if(week==6)
{
week=0;
cout<<"\n";
cout<<"\t\t";
continue;
}
week++;
}
cout<<endl<<endl<<endl;
}
}
void main()
{
int nian;
while(1)
{
cout<<"请输入你想要查询的年份~!"<<endl;
cin>>nian;
if(nian==0)
{
exit(0);
}
print4(nian);
}
}
温馨提示:内容为网友见解,仅供参考