设计c语言程序以打印任意一年的日历,要求每个季度的三个月并排打印,每个月的一个星期在一行打印
答案:2 悬赏:30 手机版
解决时间 2021-02-13 20:32
- 提问者网友:ミ烙印ゝ
- 2021-02-13 16:32
设计c语言程序以打印任意一年的日历,要求每个季度的三个月并排打印,每个月的一个星期在一行打印
最佳答案
- 五星知识达人网友:長槍戰八方
- 2021-02-13 17:22
这个程序修改修改即可啊
#include <iostream.h>
#include <stdlib.h>
int getday(int y,int m,int d)
{
return m <= 2 && (y--, m += 12),(y%100 + y%100/4 + y/100/4 - y/100*2 + 26*(m+1)/10 + d-1)%7;
}
void dispaly(int y)
{
int month[12]={31,28,31,30,31,30,31,31,30,31,30,31}, j, wday=getday(y,1,1), i=0;
for(month[1] += (y%400==0||(y%4==0&&y%100!=0));i<12 && cout<<" "<<i+1<<"月\n"<<endl<<"日\t一\t二\t三\t四\t五\t六"<<endl;wday=(wday+j)%7, cout<<endl<<endl,i++)
{
for(j=0;j<wday;cout<<" \t",j++);
for(j=0;j<month[i];cout<<j+1<<"\t", !((j+wday+1)%7) && cout<<endl, j++);
}
}
void main()
{
char week[7][3]={"日","一","二","三","四","五","六"}, atc[100];
for( int y, m, d; system("cls"), cout<<"1、输入年32313133353236313431303231363533e58685e5aeb931333332643265份打印出月份表"<<endl<<"2、计算星期"<<endl<<"0、退出"<<endl, cin>>atc; system("pause"))
{
if(atc[0] == '1' && cout<<"输入年份:") dispaly((cin>>y, y));
else if(atc[0] == '2' && (cout<<"输入年 月 日:",cin>>y>>m>>d)) cout<<"星期为:"<<week[getday(y,m,d)]<<endl;
else if(atc[0] == '0') return 0;
else cout<<"输入错误!"<<endl;
}
}
#include <iostream.h>
#include <stdlib.h>
int getday(int y,int m,int d)
{
return m <= 2 && (y--, m += 12),(y%100 + y%100/4 + y/100/4 - y/100*2 + 26*(m+1)/10 + d-1)%7;
}
void dispaly(int y)
{
int month[12]={31,28,31,30,31,30,31,31,30,31,30,31}, j, wday=getday(y,1,1), i=0;
for(month[1] += (y%400==0||(y%4==0&&y%100!=0));i<12 && cout<<" "<<i+1<<"月\n"<<endl<<"日\t一\t二\t三\t四\t五\t六"<<endl;wday=(wday+j)%7, cout<<endl<<endl,i++)
{
for(j=0;j<wday;cout<<" \t",j++);
for(j=0;j<month[i];cout<<j+1<<"\t", !((j+wday+1)%7) && cout<<endl, j++);
}
}
void main()
{
char week[7][3]={"日","一","二","三","四","五","六"}, atc[100];
for( int y, m, d; system("cls"), cout<<"1、输入年32313133353236313431303231363533e58685e5aeb931333332643265份打印出月份表"<<endl<<"2、计算星期"<<endl<<"0、退出"<<endl, cin>>atc; system("pause"))
{
if(atc[0] == '1' && cout<<"输入年份:") dispaly((cin>>y, y));
else if(atc[0] == '2' && (cout<<"输入年 月 日:",cin>>y>>m>>d)) cout<<"星期为:"<<week[getday(y,m,d)]<<endl;
else if(atc[0] == '0') return 0;
else cout<<"输入错误!"<<endl;
}
}
全部回答
- 1楼网友:独钓一江月
- 2021-02-13 17:29
这个程序修改修改即可啊
#include <iostream.h>
#include <stdlib.h>
int getday(int y,int m,int d)
{
return m <= 2 && (y--, m += 12),(y%100 + y%100/4 + y/100/4 - y/100*2 + 26*(m+1)/10 + d-1)%7;
}
void dispaly(int y)
{
int month[12]={31,28,31,30,31,30,31,31,30,31,30,31}, j, wday=getday(y,1,1), i=0;
for(month[1] += (y%400==0||(y%4==0&&y%100!=0));i<12 && cout<<" "<<i+1<<"月\n"<<endl<<"日\t一\t二\t三\t四\t五\t六"<<endl;wday=(wday+j)%7, cout<<endl<<endl,i++)
{
for(j=0;j<wday;cout<<" \t",j++);
for(j=0;j<month[i];cout<<j+1<<"\t", !((j+wday+1)%7) && cout<<endl, j++);
}
}
void main()
{
char week[7][3]={"日","一","二","三","四","五","六"}, atc[100];
for( int y, m, d; system("cls"), cout<<"1、输入年份打印出月份表"<<endl<<"2、计算星期"<<endl<<"0、退出"<<endl, cin>>atc; system("pause"))
{
if(atc[0] == '1' && cout<<"输入年份:") dispaly((cin>>y, y));
else if(atc[0] == '2' && (cout<<"输入年 月 日:",cin>>y>>m>>d)) cout<<"星期为:"<<week[getday(y,m,d)]<<endl;
else if(atc[0] == '0') return 0;
else cout<<"输入错误!"<<endl;
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯