#include<iostream>
using namespace std;
#include<iomanip>
int daysofmonth[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int Isleap_year(int year)
{
if((year%4==0&&year%100!=0)||year%400==0)
return 1;
else
return 0;
}
int get_days(int y,int m,int d)
{
int i,count=d; //公年元年1月1日是星期1
for(i=1;i<y;i++)
{
if(Isleap_year(i))
count++;
}
count+=(365*(y-1));
if(Isleap_year(y))
daysofmonth[2]=29;
for(i=1;i<m;i++)
count+=daysofmonth[i];
return count;
}
void printf_year()
{
system("cls");//清屏
int sum,year,month;
int a[10],b[10];
cout<<"你想知道哪一年的年历呢?请输入:";
cin>>year;
cout<<"======================= The calender of year "<<year<<"========================"<<endl;
int i=1;
int j;
for(i=1;i<=12/3;i++)//每一行显示三个月的月历
{
cout<<"----------------------------------------------------------------------------"<<endl;
for(int h=1;h<=3;h++)
{
int m=3*(i-1)+h;
cout<<" "<<m<<"月 ";//月份名
}
cout<<endl<<"-----------------------------------------------------------------------------"<<endl;
for( j=0;j<3;j++)
cout<<"日"<<" 一"<<" 二"<<" 三"<<" 四"<<" 五"<<" 六 "<<" ";
cout<<endl;
for( j=0;j<3;j++)
{
month=3*(i-1)+j+1;
sum=get_days(year,month,1);
sum=sum%7;
for(int m=0;m<sum;m++)
cout<<" ";
if(Isleap_year(year))
daysofmonth[2]=29;
b[j]=daysofmonth[month];
for(int k=1;k<8-sum;)
{
cout<<setw(2)<<setfill(' ')<<k<<" ";
k++;
a[j]=k;
}
cout<<" ";
}
cout<<endl;
for(int w=1;w<=5;w++)
{
for(int j=0;j<3;j++)
{
int m;
for(m=1;m<=7;m++,a[j]++)
{
if(a[j]>b[j])
break;
cout<<setw(2)<<setfill(' ')<<a[j]<<" ";
}
for(int n=1;a[j]>b[j],n<=8-m+1;n++)
cout<<" ";
if(a[j]>b[j]&&m!=8)
cout<<" ";
}
cout<<endl;
}
}
cout<<"================================================="<<endl;
}
void main()
{
printf_year();
system("pause");
}
这万年历的代码错哪了?
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
4条回答
相关推荐 更多相似问题
点击登录
提问题
悬赏问题
- ¥15 使用DWY100k数据集对UEA进行测试,出现报错:IndexError: index 125000 is out of bounds for axis 0 with size 95500
- ¥15 前端vue实现根据图片url生成pdf文件
- ¥15 RfidReader资源Q个
- ¥20 user-agent是否是唯一的,有没有可能相同
- ¥15 关于#开会#的问题,如何解决?(语言-c++)
- ¥15 关于#二十四点问题#的问题
- ¥15 运行kitex的demon出错(求大家解决)
- ¥15 开发一个类似 typora 这样的软件需要多少钱?
- ¥15 clearcase7.0安装包
- ¥15 断点回归模型月度核密度检验不连续