#include
#include
static char *title=" SUN MON TUE WED THU FRI SAT";
static char *month[12]={"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"};
static day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int leap(int year);
int week(int year);
void main()
{
int i,j,year,initweek;
do
{
cout<<"输入年份:";
cin>>year;
}while (year<=1900); //要求输入的年份必须大于1900
if(leap(year)) //闰年的二月份为29天
day[1]=29;
initweek=week(year);
cout<<"\n\t"<
{
cout<<"\n\t";
for (int k=0;k<35;k++) //输入一条横线
cout<<"-";
cout<<"\n\t"<
for (j=1;j<=day[i];j++) //输出当前月份所有的日期
{
if ((j+initweek)%7==1) //遇到星期日时换一行输出
cout<<"\n\t";
cout<
cout<<"\n\t";
for (k=0;k<35;k++) //输出一条横线
cout<<"-";
initweek=(initweek+day[i]%7)%7; //计算下一个月1号的星期号
}
cout<
//判断year年份是否为闰年
int leap(int year)
{
int leap;
if(year%400==0)
leap=1;
else if(year%4==0 && year%100!=0)
leap=1;
else leap=0;
return leap;
}
//计算year年的1月1日是星期几
int week(int year)
{
int i,leapyears=0,totalday;
for (i=1900;i
totalday=(year-1900)*365+leapyears;
//计算从1900年到当前年的前一年一共有多少天
return (totalday%7+1);
}
改部份后的可执行运用程式码:
http://96hjna.bay.livefilestore.com/y1pPk7FZFZtB-3QHnXcohomIVPBsCOZfFJ2uNVLhrP5D-hA_nEKshs_vneADD-9A2Q6DHfgMYlFf1kL5N_G10l2xQ/code.txt
------------------
从这个参考程式做修正
恩标记了