您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 质量控制/管理 > C语言程序设计--输出任意年份的日历
1.(基本题,分值75)编程序实现如下功能:输入任意一个年份的值,输出该年份的日历。要求将12个月自上而下排成一列。#includestdio.hmain(){intyear,month,day,c,Y,W,i,j,w;intt[]={31,0,31,30,31,30,31,31,30,31,30,31};printf(请输入年份);scanf(%d,&year);if(year%4==0&&year%100!=0||year%400==0)t[1]=29;elset[1]=28;for(month=1;month=12;month++){if(month3){c=((int)(year-1)/100);Y=(year-1)-((int)((year-1)/100))*100;w=((int)(c/4))-2*c+Y+((int)(Y/4))+((int)(13*(month+13)/5));W=(w+70)%7;}elseif(month=3){c=((int)(year/100));Y=year-((int)(year/100))*100;w=((int)(c/4))-2*c+Y+((int)(Y/4))+((int)(13*(month+1)/5));W=(w+70)%7;}i=W;printf(\n\n%d\n,month);printf(日一二三四五六\n);for(j=1;j=W;j++)printf();for(day=1;day=t[month-1];day++){i++;printf(%4d,day);if(i%7==0)printf(\n);}}printf(\n);}2.(拓展题,分值25)输入任意一个年份的值,输出该年份的日历。要求将12个月自上而下排成两列。#includestdio.hmain(){intyear,month,day1,day2,c,Y,W,i1,i2,j,w,k,flag1=0,flag2=0,p,q;intt[]={31,0,31,30,31,30,31,31,30,31,30,31};printf(请输入年份);scanf(%d,&year);if(year%4==0&&year%100!=0||year%400==0)t[1]=29;elset[1]=28;for(month=1;month=12;month=month+2){flag1=0;flag2=0;/*每次循环flag1;flag2的初始都应该为0*/if(month3){c=((int)(year-1)/100);Y=(year-1)-((int)((year-1)/100))*100;w=((int)(c/4))-2*c+Y+((int)(Y/4))+((int)(13*(month+13)/5));W=(w+70)%7;}elseif(month=3){c=((int)(year/100));Y=year-((int)(year/100))*100;w=((int)(c/4))-2*c+Y+((int)(Y/4))+((int)(13*(month+1)/5));W=(w+70)%7;}printf(\n\n%d%d\n,month,month+1);printf(日一二三四五六日一二三四五六\n);i1=W;/*一行一行的输出*/for(j=1;j=W;j++)/*第一行的循环不同于其他的故要单独写循环语句*/printf();for(day1=1;day1=t[month-1]&&flag1==0;day1++){i1++;printf(%4d,day1);if(i1%7==0)flag1=1;}printf();i2=(W+t[month-1])%7;for(k=1;k=((W+t[month-1])%7);k++)printf();for(day2=1;day2=t[month]&&flag2==0;day2++){i2++;printf(%4d,day2);if(i2%7==0)flag2=1;}printf(\n);for(p=8;p=50;p=p+7)/*第二行及其后面的循环*/{i1=0;flag1=0;for(day1=p-W;day1=t[month-1]&&flag1==0;day1++){i1++;printf(%4d,day1);if(i1%7==0)flag1=1;}for(q=i1;q7;q++)/*格式对齐的控制使第二列的日历每行的第一个书从同一位置开始*/printf();printf();i2=0;flag2=0;for(day2=p-(W+t[month-1])%7;day2=t[month]&&flag2==0;day2++){i2++;printf(%4d,day2);if(i2%7==0)flag2=1;}printf(\n);}}}
本文标题:C语言程序设计--输出任意年份的日历
链接地址:https://www.777doc.com/doc-4033224 .html