找了很多C++代码,都是1900~2099的,本人急需1500~2500年的
大家看到的赶紧了,明天就要交作业了。
有没有1900年以前的万年历代码
答案:1 悬赏:30 手机版
解决时间 2021-03-15 22:21
- 提问者网友:我们很暧昧
- 2021-03-14 22:59
最佳答案
- 五星知识达人网友:西风乍起
- 2021-03-15 00:23
//任意年份万年历
#include
int days[]={0,31,59,90,120,151,181,212,243,273,304,334,365};
int month[]={31,28,31,30,31,30,31,31,30,31,30,31};
char weekday[7][7]={"一","二","三","四","五","六","七"};
int week(int y,int m,int d)
{
int day=0;
day=days[m-1]+d-1;
return (y-1+(y-1)/4-(y-1)/100+(y-1)/400+day)%7;
}
void print()
{
puts("1.Week(查询某天是星期几)");
puts("2.Month(打印某月日历)");
puts("3.Calendar(打印某年日历)");
puts("4.Exit(退出)");
}
void printmonth(int y,int m)
{
int i,j,w;
w=(week(y,m,1)+1)%7;
puts(" SUN MON TUE WED THU FRI SAT");
for(i=1;i<=w;i++)
printf("%5c",' ');
for(j=i;j {
printf("%5d",j-i+1);
if(j%7==0)
puts("");
}
if((j-1)%7)
puts("");
}
int main()
{
int i,y,m,d,c;
char op[1];
print();
while(scanf("%d",&c)==1)
{
if(c==1)
{
do
{
puts("请输入年月日(XXXX,XX,XX)");
scanf("%d%d%d",&y,&m,&d);
printf("%4.4d年%2.2d月%2.2d日是星期%s,是否继续查询(Y/N)?\n",y,m,d,weekday[week(y,m,d)]);
scanf("%s",op);
}while(op[0]=='Y');
print();
}
if(c==2)
{
do
{
puts("请输入要打印的月份(XXXX)");
scanf("%d%d",&y,&m);
printf(" %4.4d年%2.2d月\n",y,m);
printmonth(y,m);
puts("是否继续打印(Y/N)?");
scanf("%s",op);
}while(op[0]=='Y');
print();
}
if(c==3)
{
do
{
puts("请输入要打印的年份(XXXX)");
scanf("%d",&y);
printf(" %4.4d\n",y);
for(i=1;i<=12;i++)
{
printf(" %2.2d月\n",i);
printmonth(y,i);
}
puts("是否继续打印(Y/N)?");
scanf("%s",op);
}while(op[0]=='Y');
print();
}
if(c==4)
{
puts("是否要真的退出(Y/N)?");
scanf("%s",op);
if(op[0]=='Y')
return 0;
else print();
}
}
}
#include
int days[]={0,31,59,90,120,151,181,212,243,273,304,334,365};
int month[]={31,28,31,30,31,30,31,31,30,31,30,31};
char weekday[7][7]={"一","二","三","四","五","六","七"};
int week(int y,int m,int d)
{
int day=0;
day=days[m-1]+d-1;
return (y-1+(y-1)/4-(y-1)/100+(y-1)/400+day)%7;
}
void print()
{
puts("1.Week(查询某天是星期几)");
puts("2.Month(打印某月日历)");
puts("3.Calendar(打印某年日历)");
puts("4.Exit(退出)");
}
void printmonth(int y,int m)
{
int i,j,w;
w=(week(y,m,1)+1)%7;
puts(" SUN MON TUE WED THU FRI SAT");
for(i=1;i<=w;i++)
printf("%5c",' ');
for(j=i;j {
printf("%5d",j-i+1);
if(j%7==0)
puts("");
}
if((j-1)%7)
puts("");
}
int main()
{
int i,y,m,d,c;
char op[1];
print();
while(scanf("%d",&c)==1)
{
if(c==1)
{
do
{
puts("请输入年月日(XXXX,XX,XX)");
scanf("%d%d%d",&y,&m,&d);
printf("%4.4d年%2.2d月%2.2d日是星期%s,是否继续查询(Y/N)?\n",y,m,d,weekday[week(y,m,d)]);
scanf("%s",op);
}while(op[0]=='Y');
print();
}
if(c==2)
{
do
{
puts("请输入要打印的月份(XXXX)");
scanf("%d%d",&y,&m);
printf(" %4.4d年%2.2d月\n",y,m);
printmonth(y,m);
puts("是否继续打印(Y/N)?");
scanf("%s",op);
}while(op[0]=='Y');
print();
}
if(c==3)
{
do
{
puts("请输入要打印的年份(XXXX)");
scanf("%d",&y);
printf(" %4.4d\n",y);
for(i=1;i<=12;i++)
{
printf(" %2.2d月\n",i);
printmonth(y,i);
}
puts("是否继续打印(Y/N)?");
scanf("%s",op);
}while(op[0]=='Y');
print();
}
if(c==4)
{
puts("是否要真的退出(Y/N)?");
scanf("%s",op);
if(op[0]=='Y')
return 0;
else print();
}
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯