万年历程序

时间:2022-10-15 04:48:11 阅读: 最新文章 文档下载
说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。
#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("请输入年月日(XXXXXXXX"); 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;


本文来源:https://www.wddqw.com/doc/8add696e3c1ec5da51e2700a.html