用c语言编写万年历程序
C语言实现万年历程序
week=(sum+1)%7; //表示该年1月1日为星期几
if(year(y)==366) days[1]=29;
printf("\n%d年日历如下:\n\n",y);
for(i=0;i<12;i++) { printf(" %d月 \n",i+1); printf(" 7 1 2 3 4 5 6\n"); printf("=====================\n"); begin=1; for(j=0;j<week;j++) printf(" "); while(begin<=days[i]) { printf("%3d",begin); begin++; week=(week+1)%7; if(week%7==0) printf("\n"); } printf("\n\n");
这篇文章主要介绍了visualstudio2000系列版本安装opengl的图文教程本文通过图文并茂的形式给大家介绍的非常详细对大家的学习或工作具有一定的参考借鉴价值需要的朋友可以参考下
C语 言 实 现 万 年 历 程 序
本文实例为大家分享了C语言实现万年历程序,供大家参考,具体内容如下
#include <stdio.h>
}
return 0; }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
C语言万年历代码
题目:年历显示。
功能要求:(1)输入一个年份,输出是在屏幕上显示该年的日历。
假定输入的年份在1940-2040年之间。
(2)输入年月,输出该月的日历。
(3)输入年月日,输出距今天还有多少天,星期几,是否是公历节日。
如下图:以下部分为代码:#include<stdio.h>#include<math.h>void part1(int x); //函数1~6为打印日历的函数void part2(int x);void part3(int x);void part4(int x);void part5(int x);void part6(int x);int weak(int x,int y); //计算1号对应的星期int weak2(int x,int y,int z); //计算星期,为函数day提供数据int year(int x); //打印日历的函数int mouth(int x); //打印月历的函数int day(int x); //查询天数的函数int distance(int x,int y,int z); //提供距离天数查询int main(){int a;char z;printf("****************************************************************\n");printf(" * *\n");printf(" * *\n");printf(" * *\n");printf(" * 欢迎使用万年历!*\n");printf(" * *\n");printf(" * *\n");printf(" * 开发:杨润*\n");printf("****************************************************************\n");x: //位置标注printf("\n");printf("请输入一个日期(Ex:20150302或201503或2015):");scanf("%d",&a);printf("\n");if((1940<=a)&&(a<=2040)){year(a);}else if((194001<=a)&&(a<=204012)){mouth(a);}else if((19400101<=a)&&(a<=20401231)){day(a);}else{printf("输入错误,请重新输入!");goto x;}printf("\n");printf("\n");printf("继续查询(y),退出(n):");scanf("%s",&z);if(z=='y'){goto x;}else{;}return 0;}int year(int x){printf("-------------------------------%d年的年历----------------------------\n",x);printf("\n");part1(x); //调用第一部分函数part2(x);part3(x);part4(x);part5(x);part6(x);printf("-----------------------------------------------------------------------\n");return 0;}int mouth(int x){int i,n,y,y2,w,week,yue2,bz1; //n表示年份,y表示月份,w,y2均为临时变量,yue2表示2月份天数n=(int)(x/100);y=(int)(x%100);printf("您现在查询的是%d年%d月\n",n,y);printf(" \n");if(y==1) //1月的情况{printf("1月Sun Mon Tue Wed Thu Fri Sat\n");printf(" ");if(n<2000) //计算小于两千的1.1星期{y2=(n-1)%100; //y2 w=(int)(y2+(y2/4)+(19/4)-38+(26*1.4));week=w%7;}if(n>=2000) //计算大于两千的1.1星期{ y2=(n-1)%100;w=(int)(y2+(y2/4)+(20/4)-40+(26*1.4));week=w%7;}for(i=0;i<week;i++){printf(" ");}bz1=1;for(i=0;i<(7-week);i++) //第一行的一月份{if(bz1<10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第二行的1月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第三行的1月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第四行的1月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第五行的1月份for(i=0;i<7;i++){if(bz1<=31){printf(" %d ",bz1);}if(bz1>31){printf(" ");}bz1=bz1+1;}printf("\n");printf(" "); //第六行的1月份for(i=0;i<7;i++){if(bz1<=31){printf(" %d ",bz1);}if(bz1>31){printf(" ");}bz1=bz1+1;}printf("\n");}if(y==2) //2月的情况{if(n%4==0){if(n%100!=0)yue2=29;else if(n%100==0&&n%400==0)yue2=29;elseyue2=28;}else{yue2=28;}printf("2月Sun Mon Tue Wed Thu Fri Sat\n");printf(" ");if(n<2000) //计算小于两千的2.1星期{y2=(n-1)%100; //y2w=(int)(y2+(y2/4)+(19/4)-38+(26*1.5));week=w%7;}if(n>=2000) //计算大于两千的2.1星期{ y2=(n-1)%100;w=(int)(y2+(y2/4)+(20/4)-40+(26*1.5));week=w%7;}for(i=0;i<week;i++){printf(" ");}bz1=1;for(i=0;i<(7-week);i++) //第一行的2月份{if(bz1<10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第二行的2月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第三行的2月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第四行的2月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第五行的2月份for(i=0;i<7;i++){if(bz1<=yue2){printf(" %d ",bz1);}if(bz1>yue2){printf(" ");}bz1=bz1+1;}printf("\n");printf(" "); //第六行的2月份for(i=0;i<7;i++){if(bz1<=yue2){printf(" %d ",bz1);}if(bz1=yue2){printf(" ");}bz1=bz1+1;}printf("\n");}//2月情况判断完毕if((y==3)||(y==5)||(y==7)||(y==8)||(y==10)||(y==12)) //31天的情况(3、5、7、8、10、12月){printf("%d月Sun Mon Tue Wed Thu Fri Sat\n",y);printf(" ");week=weak(n,y);for(i=0;i<week;i++) //第一行{printf(" ");}bz1=1;for(i=0;i<(7-week);i++){if(bz1<10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第二行for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第三行for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第四行for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第五行for(i=0;i<7;i++){if(bz1<=31){printf(" %d ",bz1);}if(bz1>31){printf(" ");}bz1=bz1+1;}printf("\n");printf(" "); //第六行for(i=0;i<7;i++){if(bz1<=31){printf(" %d ",bz1);}if(bz1>31){printf(" ");}bz1=bz1+1;}printf("\n");}if((y==4)||(y==6)||(y==9)||(y==11)) //30天的情况(4、6、9、11月){printf("%d月Sun Mon Tue Wed Thu Fri Sat\n",y);printf(" ");week=weak(n,y);for(i=0;i<week;i++) //第一行{printf(" ");}bz1=1;for(i=0;i<(7-week);i++){if(bz1<10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第二行for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第三行for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第四行for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第五行for(i=0;i<7;i++){if(bz1<=30){printf(" %d ",bz1);}if(bz1>30){printf(" ");}bz1=bz1+1;}printf("\n");printf(" "); //第六行for(i=0;i<7;i++){if(bz1<=30){printf(" %d ",bz1);}if(bz1>30){printf(" ");}bz1=bz1+1;}printf("\n");}return 0;}int day(int x){int n,y,y1,t,week; //n为年,y为yue,y1位计算y的临时变量,t为天,week为周,p为距离今天天数n=x/10000;y1=x%10000;y=y1/100;t=x%100;printf("\n");printf("您查询的是:%d年%d月%d日",n,y,t);week=weak2(n,y,t);switch(week) //根据返回数值判断星期{case 0:printf("星期日");break;case 1:printf("星期一");break;case 2:printf("星期二");break;case 3:printf("星期三");break;case 4:printf("星期四");break;case 5:printf("星期五");break;case 6:printf("星期六");break;}if(y==1&&t==1) printf("这天是元旦"); //查询节日if(y==2&&t==2) printf("这天是世界湿地日");if(y==2&&t==14) printf("这天是情人节");if(y==3&&t==3) printf("这天是全国爱耳日");if(y==3&&t==5) printf("这天是青年志愿者服务日");if(y==3&&t==8) printf("这天是国际妇女节");if(y==3&&t==9) printf("这天是保护母亲河日");if(y==3&&t==12) printf("这天是中国植树节");if(y==3&&t==14) printf("这天是白色情人节\n");if(y==3&&t==14) printf("这天是国际警察日");if(y==3&&t==15) printf("这天是世界消费者权益日");if(y==3&&t==21) printf("这天是世界森林日\n");if(y==3&&t==21) printf("这天是世界睡眠日");if(y==3&&t==22) printf("这天是世界水日");if(y==3&&t==23) printf("这天是世界气象日");if(y==3&&t==24) printf("这天是世界防治结核病日");if(y==4&&t==1) printf("这天是愚人节");if(y==4&&t==5) printf("这天是清明节");if(y==4&&t==7) printf("这天是世界卫生日");if(y==4&&t==22) printf("这天是世界地球日");if(y==4&&t==26) printf("这天是世界知识产权日");if(y==5&&t==1) printf("这天是国际劳动节");if(y==5&&t==3) printf("这天是世界哮喘日");if(y==5&&t==4) printf("这天是中国青年节");if(y==5&&t==8) printf("这天是世界红十字日");if(y==5&&t==12) printf("这天是国际护士节");if(y==5&&t==15) printf("这天是国际家庭日");if(y==5&&t==17) printf("这天是世界电信日");if(y==5&&t==20) printf("这天是全国学生营养日");if(y==5&&t==23) printf("这天是国际牛奶日");if(y==5&&t==31) printf("这天是世界无烟日");if(y==6&&t==1) printf("这天是国际儿童节");if(y==6&&t==5) printf("这天是世界环境日");if(y==6&&t==6) printf("这天是全国爱眼日");if(y==6&&t==17) printf("这天是世界防治荒漠化和干旱日"); if(y==6&&t==23) printf("这天是国际奥林匹克日");if(y==6&&t==25) printf("这天是全国土地日");if(y==6&&t==26) printf("这天是国际禁毒日");if(y==7&&t==1) printf("这天是中国共产党诞生日\n");if(y==7&&t==1) printf("这天是国际建筑日");if(y==7&&t==7) printf("这天是中国人民抗日战争纪念日"); if(y==7&&t==11) printf("这天是世界人口日");if(y==8&&t==1) printf("这天是中国人民解放军建军节");if(y==8&&t==12) printf("这天是国际青年节");if(y==9&&t==8) printf("这天是国际扫盲日");if(y==9&&t==10) printf("这天是中国教师节");if(y==9&&t==16) printf("这天是中国脑健康日\n");if(y==9&&t==16) printf("这天是国际臭氧层保护日");if(y==9&&t==20) printf("这天是全国爱牙日");if(y==9&&t==21) printf("这天是世界停火日");if(y==9&&t==27) printf("这天是世界旅游日");if(y==10&&t==1) printf("这天是中华人民共和国国庆节\n");if(y==10&&t==1) printf("这天是国际音乐日\n");if(y==10&&t==1) printf("这天是国际老年人日");if(y==10&&t==4) printf("这天是世界动物日");if(y==10&&t==5) printf("这天是世界教师日");if(y==10&&t==8) printf("这天是全国高血压日");if(y==10&&t==9) printf("这天是世界邮政日");if(y==10&&t==10) printf("这天是世界精神卫生日");if(y==10&&t==14) printf("这天是世界标准日");if(y==10&&t==15) printf("这天是国际盲人节\n");if(y==10&&t==15) printf("这天是世界农村妇女日");if(y==10&&t==16) printf("这天是世界粮食日");if(y==10&&t==17) printf("这天是国际消除贫困日");if(y==10&&t==24) printf("这天是联合国日\n");if(y==10&&t==24) printf("这天是世界发展新闻日");if(y==10&&t==28) printf("这天是中国男性健康日");if(y==10&&t==29) printf("这天是国际生物多样性日");if(y==10&&t==31) printf("这天是万圣节");if(y==11&&t==8) printf("这天是中国记者节");if(y==11&&t==9) printf("这天是消防宣传日");if(y==11&&t==14) printf("这天是世界糖尿病日");if(y==11&&t==17) printf("这天是国际大学生节");if(y==11&&t==25) printf("这天是国际消除对妇女的暴力日");if(y==12&&t==1) printf("这天是世界爱滋病日");if(y==12&&t==3) printf("这天是世界残疾人日");if(y==12&&t==4) printf("这天是全国法制宣传日");if(y==12&&t==9) printf("这天是世界足球日");if(y==12&&t==25) printf("这天是圣诞节");if(y==12&&t==29) printf("这天是国际生物多样性日");printf("\n");distance(n,y,t);return 0;}//计算今天日期的函数结尾void part1(int x) //第一部分{int i,week,week2,y,w,b1,bz1,bz2;//week,week2用于计算1.1的星期,bz1和bz2为日期的递增b1=7;printf("1月Sun Mon Tue Wed Thu Fri Sat");printf(" ");printf("7月Sun Mon Tue Wed Thu Fri Sat\n");printf(" ");if(x<2000) //计算小于两千的1.1星期{ y=(x-1)%100;w=(int)(y+(y/4)+(19/4)-38+(26*1.4));week=w%7;}if(x>=2000) //计算大于两千的1.1星期{ y=(x-1)%100;w=(int)(y+(y/4)+(20/4)-40+(26*1.4));week=w%7;}week2=weak(x,b1); //调用计算星期的函数(7.1) for(i=0;i<week;i++){printf(" ");}bz1=1,bz2=1;for(i=0;i<(7-week);i++){if(bz1<10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印7月的for(i=0;i<=week2;i++){printf(" ");}for(i=0;i<(7-week2);i++){if(bz2<10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第一行打印完毕printf(" "); //第二行的1月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印7月的第二行for(i=0;i<7;i++){if(bz2<10){printf(" %d ",bz2);}if(bz2>=10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第二行打印结束printf(" "); //第三行的1月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印7月的第三行for(i=0;i<7;i++){ if(bz2<10){printf(" %d ",bz2);}if(bz2>=10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第三行打印结束printf(" "); //第四行的1月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印7月的第四行for(i=0;i<7;i++){if(bz2<10){printf(" %d ",bz2);}if(bz2>=10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第四行打印结束printf(" "); //第五行的1月份for(i=0;i<7;i++){if(bz1<=31){printf(" %d ",bz1);}if(bz1>31){printf(" ");}bz1=bz1+1;}printf(" "); //从这里开始打印7月的第五行for(i=0;i<7;i++){if(bz2<=31){printf(" %d ",bz2);}if(bz2>31){printf(" ");}bz2=bz2+1;}printf("\n"); //第五行打印结束printf(" "); //第六行的1月份for(i=0;i<7;i++){if(bz1<=31){printf(" %d ",bz1);}if(bz1>31){printf(" ");}bz1=bz1+1;}printf(" "); //从这里开始打印7月的第六行for(i=0;i<7;i++){if(bz2<=31){printf(" %d ",bz2);}if(bz2>31){printf(" ");}bz2=bz2+1;}printf("\n"); //第六行打印结束} //第一部分1月、7月打印完毕!void part2(int x) //第二部分2月、8月开始打印!//第二部分{int i,week,week2,y,w,b1,bz1,bz2,yue2;//week,week2用于计算2.1的星期,bz1和bz2为日期的递增b1=8; //表示当前部分的月份printf("2月Sun Mon Tue Wed Thu Fri Sat");printf(" ");printf("8月Sun Mon Tue Wed Thu Fri Sat\n");printf(" ");if(x%4==0){if(x%100!=0)yue2=29;else if(x%100==0&&x%400==0)yue2=29;elseyue2=28;}else{yue2=28;}if(x<2000) //计算小于两千的1.1星期{ y=(x-1)%100;w=(int)(y+(y/4)+(19/4)-38+(26*1.5));week=w%7;}if(x>=2000) //计算大于两千的1.1星期{ y=(x-1)%100;w=(int)(y+(y/4)+(20/4)-40+(26*1.5));week=w%7;}week2=weak(x,b1); //调用计算星期的函数(7.1) for(i=0;i<week;i++){printf(" ");}bz1=1,bz2=1;for(i=0;i<(7-week);i++){if(bz1<10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印8月的第一行for(i=0;i<=week2;i++){printf(" ");}for(i=0;i<(7-week2);i++){if(bz2<10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第一行打印完毕printf(" "); //2月份的第二行for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印8月的第二行for(i=0;i<7;i++){if(bz2<10){printf(" %d ",bz2);}if(bz2>=10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第二行打印结束printf(" "); //第三行的2月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印8月的第三行for(i=0;i<7;i++){ if(bz2<10){printf(" %d ",bz2);}if(bz2>=10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第三行打印结束printf(" "); //第四行的2月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印8月的第四行for(i=0;i<7;i++){if(bz2<10){printf(" %d ",bz2);}if(bz2>=10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第四行打印结束printf(" "); //第五行的2月份for(i=0;i<7;i++){if(bz1<=yue2){printf(" %d ",bz1);}if(bz1>yue2){printf(" ");}bz1=bz1+1;}printf(" "); //从这里开始打印8月的第五行for(i=0;i<7;i++){if(bz2<=31){printf(" %d ",bz2);}if(bz2>31){printf(" ");}bz2=bz2+1;}printf("\n"); //第五行打印结束printf(" "); //第六行的2月份for(i=0;i<7;i++){if(bz1<=yue2){printf(" %d ",bz1);}if(bz1>yue2){printf(" ");}bz1=bz1+1;}printf(" "); //从这里开始打印8月的第六行for(i=0;i<7;i++){if(bz2<=31){printf(" %d ",bz2);}if(bz2>31){printf(" ");}bz2=bz2+1;}printf("\n"); //第六行打印结束}void part3(int x) //第三部分{int i,week,week2,a1,b1,bz1,bz2;//week,week2用于计算1.1的星期,bz1和bz2为日期的递增a1=3,b1=9; //表示当前不封的月份printf("3月Sun Mon Tue Wed Thu Fri Sat");printf(" ");printf("9月Sun Mon Tue Wed Thu Fri Sat\n");printf(" ");week=weak(x,a1); //调用计算星期的函数(3.1)week2=weak(x,b1); //调用计算星期的函数(8.1)for(i=0;i<week;i++){printf(" ");}bz1=1,bz2=1;for(i=0;i<(7-week);i++){if(bz1<10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印9月的for(i=0;i<=week2;i++){printf(" ");}for(i=0;i<(7-week2);i++){if(bz2<10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第一行打印完毕printf(" "); //第二行的3月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印9月的第二行for(i=0;i<7;i++){if(bz2<10){printf(" %d ",bz2);}if(bz2>=10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第二行打印结束printf(" "); //第三行的3月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印9月的第三行for(i=0;i<7;i++){ if(bz2<10){printf(" %d ",bz2);}if(bz2>=10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第三行打印结束printf(" "); //第四行的3月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印9月的第四行for(i=0;i<7;i++){if(bz2<10){printf(" %d ",bz2);}if(bz2>=10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第四行打印结束printf(" "); //第五行的3月份for(i=0;i<7;i++){if(bz1<=31){printf(" %d ",bz1);}if(bz1>31){printf(" ");}bz1=bz1+1;}printf(" "); //从这里开始打印9月的第五行for(i=0;i<7;i++){if(bz2<=30){printf(" %d ",bz2);}if(bz2>30){printf(" ");}bz2=bz2+1;}printf("\n"); //第五行打印结束printf(" "); //第六行的3月份for(i=0;i<7;i++){if(bz1<=31){printf(" %d ",bz1);}if(bz1>31){printf(" ");}bz1=bz1+1;}printf(" "); //从这里开始打印9月的第六行for(i=0;i<7;i++){if(bz2<=30){printf(" %d ",bz2);}if(bz2>30){printf(" ");}bz2=bz2+1;}printf("\n"); //第六行打印结束}void part4(int x) //第四部分{int i,week,week2,a1,b1,bz1,bz2;//week,week2用于计算1.1的星期,bz1和bz2为日期的递增a1=4,b1=10; //表示当前不封的月份printf("4月Sun Mon Tue Wed Thu Fri Sat");printf(" ");printf("10月Sun Mon Tue Wed Thu Fri Sat\n");printf(" ");week=weak(x,a1); //调用计算星期的函数(4.1)week2=weak(x,b1); //调用计算星期的函数(10.1)for(i=0;i<week;i++){printf(" ");}bz1=1,bz2=1;for(i=0;i<(7-week);i++){if(bz1<10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印4月的for(i=0;i<=week2;i++){printf(" ");}for(i=0;i<(7-week2);i++){if(bz2<10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第一行打印完毕printf(" "); //第二行的4月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印10月的第二行for(i=0;i<7;i++){if(bz2<10){printf(" %d ",bz2);}if(bz2>=10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第二行打印结束printf(" "); //第三行的4月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印10月的第三行for(i=0;i<7;i++){ if(bz2<10){printf(" %d ",bz2);}if(bz2>=10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第三行打印结束printf(" "); //第四行的4月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印10月的第四行for(i=0;i<7;i++){if(bz2<10){printf(" %d ",bz2);}if(bz2>=10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第四行打印结束printf(" "); //第五行的10月份for(i=0;i<7;i++){if(bz1<=30){printf(" %d ",bz1);}if(bz1>30){printf(" ");}bz1=bz1+1;}printf(" "); //从这里开始打印10月的第五行for(i=0;i<7;i++){if(bz2<=31){printf(" %d ",bz2);}if(bz2>31){printf(" ");}bz2=bz2+1;}printf("\n"); //第五行打印结束printf(" "); //第六行的4月份for(i=0;i<7;i++){if(bz1<=30){printf(" %d ",bz1);}if(bz1>30){printf(" ");}bz1=bz1+1;}printf(" "); //从这里开始打印10月的第六行for(i=0;i<7;i++){if(bz2<=31){printf(" %d ",bz2);}if(bz2>31){printf(" ");}bz2=bz2+1;}printf("\n"); //第六行打印结束}void part5(int x) //第五部分{int i,week,week2,a1,b1,bz1,bz2;//week,week2用于计算1.1的星期,bz1和bz2为日期的递增a1=5,b1=11; //表示当前不封的月份printf("5月Sun Mon Tue Wed Thu Fri Sat");printf(" ");printf("11月Sun Mon Tue Wed Thu Fri Sat\n");printf(" ");week=weak(x,a1);week2=weak(x,b1); //调用计算星期的函数(11.1)for(i=0;i<week;i++){printf(" ");}bz1=1,bz2=1;for(i=0;i<(7-week);i++){if(bz1<10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印11月的for(i=0;i<=week2;i++){printf(" ");}for(i=0;i<(7-week2);i++){if(bz2<10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第一行打印完毕printf(" "); //第二行的5月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印11月的第二行for(i=0;i<7;i++){if(bz2<10){printf(" %d ",bz2);}if(bz2>=10)bz2=bz2+1;}printf("\n"); //第二行打印结束printf(" "); //第三行的5月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印11月的第三行for(i=0;i<7;i++){ if(bz2<10){printf(" %d ",bz2);}if(bz2>=10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第三行打印结束printf(" "); //第四行的5月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印11月的第四行for(i=0;i<7;i++){if(bz2<10){printf(" %d ",bz2);}if(bz2>=10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第四行打印结束printf(" "); //第五行的5月份for(i=0;i<7;i++){if(bz1<=31){printf(" %d ",bz1);}if(bz1>31)bz1=bz1+1;}printf(" "); //从这里开始打印11月的第五行for(i=0;i<7;i++){if(bz2<=30){printf(" %d ",bz2);}if(bz2>30){printf(" ");}bz2=bz2+1;}printf("\n"); //第五行打印结束printf(" "); //第六行的5月份for(i=0;i<7;i++){if(bz1<=31){printf(" %d ",bz1);}if(bz1>31){printf(" ");}bz1=bz1+1;}printf(" "); //从这里开始打印11月的第六行for(i=0;i<7;i++){if(bz2<=30){printf(" %d ",bz2);}if(bz2>30){printf(" ");}bz2=bz2+1;}printf("\n"); //第六行打印结束}void part6(int x) //第六部分{int i,week,week2,a1,b1,bz1,bz2;//week,week2用于计算1.1的星期,bz1和bz2为日期的递增a1=6,b1=12; //表示当前不封的月份printf("6月Sun Mon Tue Wed Thu Fri Sat");printf(" ");printf("12月Sun Mon Tue Wed Thu Fri Sat\n");printf(" ");week=weak(x,a1);week2=weak(x,b1); //调用计算星期的函数(12.1)for(i=0;i<week;i++){printf(" ");}。
c语言万年历程序
#include <stdio.h>#include <stdlib.h>#include <ctype.h>int leap (int year) ;//判断是否为闰年int days_month (int month,int year) ;//判断这个月的天数int menu_select();/*void f(){int day,month,year,sum,leap,S;printf("\n请输入年月日\n");scanf("%d%d%d",&year,&month,&day);switch(month){case 1:sum=0;break;case 2:sum=31;break;case 3:sum=59;break;case 4:sum=90;break;case 5:sum=120;break;case 6:sum=151;break;case 7:sum=181;break;case 8:sum=212;break;case 9:sum=243;break;case 10:sum=273;break;case 11:sum=304;break;case 12:sum=334;break;default:printf("data error");break;}sum=sum+day;if(year%400==0||(year%4==0&&year%100!=0))leap=1;else leap=0;if(leap==1&&month>2)sum++;S=(year-1+(year-1)/4-(year-1)/100+(year-1)/400+sum)%7; //X表示年份,C是该年份元旦开始到这一日的天数//S/7的系数就是星期数//01printf("%d",S);switch(S){case 1:printf("星期一\n");break;case 2:printf("星期二\n");break;case 3:printf("星期三\n");break;case 4:printf("星期四\n");break;case 5:printf("星期五\n");break;case 6:printf("星期六\n");break;case 0:printf("星期日\n");break;}}*/int Leap(int year){ int leap;if(year%400==0||(year%4==0&&year%100!=0))leap=1;else leap=0;return leap;}int SU(int sum,int year){int S;S=(year-1+(year-1)/4-(year-1)/100+(year-1)/400+sum)%7;return S;}int Sum(int year,int month,int day=1){int sum,leap;switch(month){case 1:sum=0;break;case 2:sum=31;break;case 3:sum=59;break;case 4:sum=90;break;case 5:sum=120;break;case 6:sum=151;break;case 7:sum=181;break;case 8:sum=212;break;case 9:sum=243;break;case 10:sum=273;break;case 11:sum=304;break;case 12:sum=334;break;default:printf("data error");break;}sum=sum+day;leap=Leap(year);if(leap==1&&month>2)sum++;return sum;}void Print(int S){switch(S){case 1:printf("星期一\n");break;case 2:printf("星期二\n");break;case 3:printf("星期三\n");break;case 4:printf("星期四\n");break;case 5:printf("星期五\n");break;case 6:printf("星期六\n");break;case 0:printf("星期日\n");break;}}void Fun1(){int day,month,year,sum,S;printf("\n请输入年月日\n");scanf("%d%d%d",&year,&month,&day);sum=Sum(year,month,day);S=SU(sum,year);Print(S);}void Fun2(){int i,j=1,k=1,a,b,month,year,sum;printf("\n 输入年月:\n");scanf("%d%d",&year,&month);b=days_month(month,year);sum=Sum(year,month);a=SU(sum,year);printf("*************************************\n");printf(" Sun Mon Tue Wed Thu Fri Sat \n");if(a==7){for(i=1;i<=b;i++){printf("%4d",i);if(i%7==0){printf("\n");}}}if(a!=7){while (j<=4*a){printf(" ");j++;}for(i=1;i<=b;i++){printf("%4d",i);if(i==7*k-a){printf("\n");k++;}}}printf("\n*************************************\n");printf("\n");}int days_month (int month,int year){if(month==1||month==3||month==5||month==7||month==8||month==10||month==12) return 31;if(month==4||month==6||month==9||month==11)return 30;if(month==2&&Leap(year)==1) return 29;else return 28;}void main(){for(;;){switch(menu_select()){case 1:printf("输入年月日计算该月第一天是星期几\n");Fun1();break;case 2:printf("打印任意日历\n");Fun2();break;case 3:printf("谢谢使用!\n");exit(0);}}}int menu_select(){ system("cls");char s;int cn;printf("1. 输入年月日计算该月第一天是星期几\n");printf("2. 打印任意日历\n");printf("3.谢谢使用! \n");printf("input 1-3:");do {s=getchar();cn=(int)s-48;}while(cn<0||cn>6);return cn;}。
C语言程序设计 万年历程序
#include"stdio.h"int mon_day[]={31,28,31,30,31,30,31,31,30,31,30,31};int judge(int year,int month){if(month==1||month==3||month==5||month==7||month==8||month==10||month ==12)return(1);else if(month==2){if(year%4!=0||year%100==0&&year%400!=0)return(2);else return(3);}else return(4);}void show2(){int year,i,j,a,n,m,k;char ** p;char * week[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};char*month[]={"January","February","March","April","May","June","July","Augu st","September","October","November","December"};printf("please inter the year:");scanf("%d",&year);printf("\n");printf("the calendar of the year%d.",year);printf("\n");a=(year+(year-1)/4-(year-1)/100+(year-1)/400)%7;for(i=0;i<12;i++){n=judge(year,i+1);p=month+i;printf("%s\n",*p);printf("\n");for(j=0;j<7;j++){p=week+j;printf("%6s",*p);}printf("\n");for(k=0;k<a;k++)printf(" ");for(m=1;m<32;m++){printf("%6d",m);if((a+m)%7==0)printf("\n");if(n==1&&m==31) break;else if(n==2&&m==28) break;else if(n==3&&m==29) break;else if(n==4&&m==30) break;}a=(a+m)%7;/*计算出下个月的第一天是星期几*/printf("\n");printf("**************************************************");printf("\n");}}void show(){printf("******************************\n");printf("1.某年某月某日是星期几\n2.是否闰年\n3.某年某月的最大天数\n4.打印该月日历\n5.退出\n");printf("******************************\n");}int show1(int y,int m,int d){int i,R,sum=0;for(i=0;i<m-1;i++)sum=sum+mon_day[i];sum=sum+d;if((y%4 == 0 &&y%100 != 0)||(y%400 == 0)&&m>2)sum=sum+1;R=(5+(y+1)+(y-1)/4-(y-1)/100+(y-1)/400+sum)%7;if(R==0)R=7;return R;}int leap(int y){if((y%4 == 0 &&y%100 != 0)||(y%400 == 0))return 1;elsereturn 0;}int max_day(int y,int m){int X;if(leap(y)==1&&m==2)X=29 ;//printf("该年该月最大天数:29");elseX=mon_day[m-1];//printf("%d",mon_day[m-1]);return X;}void main(){int year,month,day,i;F:show();printf("请选择:");scanf("%d",&i);switch(i){case 1:printf("请输入年、月,日:");scanf("%d%d%d",&year,&month,&day);printf("%d-%d-%d是星期%d\n",year,month,day,show1(year,month,day));break;case 2:printf("请输入年份:");scanf("%d",&year);if(leap(year)==1)printf("该年是闰年.\n");elseprintf("该年不是闰年\n");break;case 3:printf("请输入年、月:");scanf("%d%d",&year,&month);printf("该月最大天数:%d",max_day(year,month)); printf("\n");break;case 4:show2();break;case 5:return 0;break;}goto F;}。
万年历——C语言编写
万年历的制作,C语言编写!!以下是代码:#include<iostream>#include<cmath>using namespace std;int i,c,day,year,k,a[50];void f1(int x) //大月{for( i=0;i<50;i++)a[i]=33;for(i=k-1;i>=0;i--)a[i]='\000'; //1 号前均为空格for(i=k;i<31+k;i++)a[i]=a[i-1]+1;}void f2(int x) //小月{for( i=0;i<50;i++)a[i]=33;for(i=k-1;i>=0;i--)a[i]='\000';for(i=k;i<30+k;i++)a[i]=a[i-1]+1;}void f3(int x) //闰年二月{for( i=0;i<50;i++)a[i]=33;for(i=k-1;i>=0;i--)a[i]='\000';for(i=k;i<29+k;i++)a[i]=a[i-1]+1;}void f4(int x) //非闰年二月{for( i=0;i<50;i++)a[i]=33;for(i=k-1;i>=0;i--)a[i]='\000';for(i=k;i<28+k;i++)a[i]=a[i-1]+1;}void g(int y[],int z) // 输出日历表{cout<<" 日"<<'\t'<<" 一"<<'\t'<<" 二"<<'\t'<<" 三"<<'\t'<<" 四"<<'\t'<<" 五"<<'\t'<<"六"<<endl;for(i=0;i<50;i++){if(a[i]==0)cout<<(char)a[i]<<'\t';if(a[i]!=0&&a[i]!=33)cout<<a[i]<<'\t';else ;if(i%7==0)cout<<endl;}cout<<endl<<endl<<endl;}int main(){int s,count=0;cout<<"请输入年份:";cin>>year;cout<<endl;c=year;for(s=1;s<=year;s++)if(((s-1)%4==0&&(s-1)%100!=0)||(s-1)%400==0)count++; day=365*c+count; //相差天数cout<<"*********************"<<year<<"年日历*********************";cout<<endl<<endl<<endl<<endl;k=(day%7+6)%7+1;cout<<"一月"<<endl<<endl;f1(k);g(a,50);if((year%4==0&&year%100!=0)||year%400==0){k=((day+31)%7+6)%7+1;cout<<"二月"<<endl<<endl;f3(k);g(a,50);day=day+31+29;}else //非闰年二月{k=((day+31)%7+6)%7+1;cout<<"二月"<<endl<<endl;f4(k);g(a,50);day=day+31+28;}k=(day%7+6)%7+1;cout<<"三月"<<endl<<endl;f1(k);g(a,50);k=((day+31)%7+6)%7+1;cout<<"四月"<<endl<<endl;f2(k);g(a,50);k=((day+31+30)%7+6)%7+1;cout<<"五月"<<endl<<endl;f1(k); g(a,50);k=((day+31+30+31)%7+6)%7+1;cout<<"六月"<<endl<<endl;f2(k);g(a,50);k=((day+31+30+31+30)%7+6)%7+1;cout<<"七月"<<endl<<endl;f1(k);g(a,50);k=((day+31+30+31+30+31)%7+6)%7+1;cout<<"八月"<<endl<<endl;f1(k);g(a,50);k=((day+31+30+31+30+31+31)%7+6)%7+1;cout<<"九月"<<endl<<endl;f2(k);g(a,50);k=((day+31+30+31+30+31+31+30)%7+6)%7+1;cout<<"十月"<<endl<<endl;f1(k);g(a,50);k=((day+31+30+31+30+31+31+30+31)%7+6)%7+1;cout<<"十一月"<<endl<<endl; f2(k);g(a,50);k=((day+31+30+31+30+31+31+30+31+30)%7+6)%7+1;cout<<"十二月"<<endl<<endl;f1(k);g(a,50);return 0;}。
c语言万年历
c语言万年历#include<stdio.h>main(){for(;;){int nian,yue,a,b,m,c,_m=28;long e;printf("请输入年份:");scanf("%d",&nian);e=nian;e=e-1;e=(e*365+e/4)%7;m=e;if((nian%4==0)||(nian%100==0)&&(nian%400!=0)) //求出nian是否为闰年//m++;printf("%d的日历:",nian);for(yue=1;yue<=12;yue++){if(yue==1||yue==3||yue==5||yue==7||yue==8||yue==10||yue==12){c=0;printf("\n");printf(" %d月\n",yue);printf(" 日一二三四五六\n");for(b=1;b<=m;b++){c++;printf(" ");}for(a=1;a<=31;a++){c++;if(c%7-1==0&&c!=1)printf("\n");if(a<10)printf(" ");printf(" %d ",a);m++;if(m==7)m=0;}printf("\n");}else{if(yue==4||yue==6||yue==9||yue==11||yue==2){if(yue==2){c=0;printf("\n");printf(" %d月\n",yue);printf(" 日一二三四五六\n");for(b=1;b<=m;b++){c++;printf(" ");}for(a=1;a<=_m;a++){c++;if(c%7-1==0&&c!=1)printf("\n");if(a<10)printf(" ");printf(" %d ",a);m++;if(m==7)m=0;}printf("\n");}else{c=0;printf("\n");printf(" %d月\n",yue);printf(" 日一二三四五六\n");for(b=1;b<=m;b++){c++;printf(" ");}for(a=1;a<=30;a++){c++;if(c%7-1==0&&c!=1)printf("\n");if(a<10)printf(" ");printf(" %d ",a);m++;if(m==7)m=0;}printf("\n");} } }} } }。
C语言程序 万年历编程
{if (a%400==0)
ya=1;
}
else ya=1;
}
else ya=0;
}
if (ya==1||b==2)
c=28;
else c=29;
switch (b)
{
case 1:case 3:case 5:case 7:case 8:case 12:c=31;break;
case 2:x=29;break;
case 4: case 6: case 9: case 10: case 11:x=30;break;
}
wa=week(y,a,1);
if (wa=="星期日") j=0;
else if (wa=="星期一") j=1;
else if (wa=="星期二") j=2;
#include<math.h>
#include<stdio.h>
//求某个日期对应的星期
char w[][7]={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
int i,j,m,d,y;
char week(int a,int b,int c) //定义星期函数
else if (wa=="星期三") j=3;
else if (wa=="星期四") j=4;
else if (wa=="星期五") j=5;
(完整版)C语言万年历
说明部分
在TC或VC6.0中编译程序,编译成功后,通过命令行向编译生成的可执行文件(.exe)传递参数,在命令行中输入该执行文件的路径名称,然后再输入传入的参数,回车,就会显示出运行结果,效果如图1.1所示。
图1.1万年历运行界面
代码部分
#include <stdio.h>
main(int a,char **date)
}
if (day<0||day>month)
{
printf ("\n ERROR! the entered DAY is invalid\n");
exit (0);
}
week=(dy+dm+day-1+6)%7;
if(week<0)
week+=7;
if (day>0) /***判定查看类型***/
{
if (d==-1) year=year*10+(date[1][i]-'0');
if (d==0) month=month*10+(date[1][i]-'0');
if (d==1) day=day*10+(date[1][i]-'0');
i++;
}
if (month<1||month>12)/*若月份传入错误数字*/
else
d=(year-2000)/4-(year-2000)/100+(year-2000)/400;
dy=(year-2000)+d; /***该年1月1号到2000年1月1号的"星期差" ***/
用c语言编写万年历
{
case 1:sum=0;break;
case 2:sum=31;break;
case 3:sum=59;break;
case 4:sum=90;break;
case 5:sum=120;break;
else goto loop2;
loop1: for(i=1901;i<year;i++)
{
if(i%400==0||(i%4==0&&i%100!=0))
n++;
}
days=(year-1901-n)*365+n*366;
case 11:sum=304;break;
case 12:sum=334;break;
default:printf("一年内只能有12个月!请重新输入!\n");goto redo;
case 3:printf("\t 五月 %d\t\t 六月 %d\n",year,year);break;
case 4:printf("\t 七月 %d\t\t 八月 %d\n",year,year);break;
goto redo;
}
if(month==6&&(day>=31||day<=0))
{
printf("输入有误!6月只能有30天!\n");
goto redo;
}
if(month==7&&(day>=32||day<=0))
{
printf("输入有误!7月只能有31天!\n");
C语言万年历(代码+说明)
/*本程序在Microsoft Visual Studio 2010 旗舰版中测试通过*/ #include "stdio.h"#include "stdlib.h"#include "time.h"#include "conio.h"#define KEYUP 72//宏定义键盘的键值(↑)#define KEYDOWN 80//宏定义键盘的键值(↓)#define KEYLEFT 75//宏定义键盘的键值(←)#define KEYRIGHT 77//宏定义键盘的键值(→)//函数声明部分const int isLeap(int year);const int getMonthDays(int year,int month);const int yearDays(int year);void printCalendar(int year,int month);void main(){int year,month;int action = 0;//获取本地当前的年份和月份time_t timep;struct tm *p;time(&timep);p = localtime(&timep);year = p->tm_year+1900;//获取本地当前的年份month = p->tm_mon + 1;//获取本地当前的月份while(1){printf("\t\t %d 年%d 月\n",year,month);printCalendar(year,month);action = getch();system("cls");switch(action){case KEYUP:year++;break;case KEYDOWN:year--;break;case KEYLEFT:month--;if(month < 1){month = 12;}break;case KEYRIGHT:month++;if(month > 12){month = 1;}break;}}}//判断year 是否是润年返回1 为闰年const int isLeap(int year){if(year%4==0&&year%100!=0||year%400==0){ return 1;}else{return 0;}}/*计算year 年的month 月是多少天*返回值:整型,天数*/const int getMonthDays(int year,int month){ switch(month){case 1:case 3:case 5:case 7:case 8:case 10:case 12:return 31;break;case 4:case 6:case 9:case 11:return 30;break;case 2:if(isLeap(year)){return 29;}else{return 28;}break;default:return 0;break;}}//计算year 年的天数const int yearDays(int year){if(isLeap(year)){return 366;}else{return 365;}}/*判断year 年month 月day 天时星期几*返回值:0,1,2,3,4,5,6*/const int isWeek(int year,int month,int day){ int days = 0;int i;//计算前year 年有多少天for(i=1;i<year;i++){days = days + yearDays(i);}//计算year 年的前month 个月有多少天for(i=1;i<month;i++){days = days + getMonthDays(year,i);}//从公元1 年days = days + day;return days%7;}//按日历的格式打印year 年month 月的日历void printCalendar(int year,int month){const char *week[]= {"日","一","二","三","四","五","六"};int i;int row = 0;for(i=0;i<7;i++){printf("%s\t",week[i]);}printf("\n");//判断year 年month 月1 日时星期几for(i=0;i<isWeek(year,month,1);i++){printf("\t");}for(i=0;i<getMonthDays(year,month);i++){ printf("%d\t",i+1);//如果是星期六就换行打印日期if(isWeek(year,month,i+1) == 6){row ++;if(row == 2){printf(" ↑");}if(row == 3){printf("←→");}if(row == 4){printf(" ↓");}printf("\n\n");}}printf("\n");}CreateDBW制作2012年12月7日。
c语言基础代码编写的简单的万年历程序
#include<stdio.h>void print(int x,int y); //打印程序x表示这个月的总天数y表示这个月的1号的星期int month_day(int x,int y); //计算该月的天数x表示年份y表示月份int run(int y); //判断闰年y表示年份int month_cha(int x,int y); //每月一号的星期x表示年份y表示月份int year_cha(int x); //每年的一月一号的星期x表示年份void main(){int year,month,day,cha;char key='y';while(key=='y'){printf("请输入年月:");scanf("%d%d",&year,&month);day=month_day(year,month);cha=month_cha(year,month);print(day,cha);printf("是否继续输入(y/n):");scanf("%c",&key);scanf("%c",&key);}}void print(int x,int y){int i,j;printf("Sun Mon Tue Wed Thu Fri Sat\n");for(i=0;i<y;i++) //打印空缺部分printf("\t");for(j=1;j<=x;j++,i++){printf("%d\t",j);if(i%7==6){printf("\n");}}printf("\n");}int run(int y){int r;if(y%4!=0)r=0;else if((y%100==0)&&(y%400)!=0)r=0;elser=1;return r;}int month_day(int x,int y){int day;switch(y){case 1: day=31; break;case 2: day=28+run(x); break;case 3: day=31; break;case 4: day=30; break;case 5: day=31; break;case 6: day=30; break;case 7: day=31; break;case 8: day=31; break;case 9: day=30; break;case 10: day=31; break;case 11: day=30; break;case 12: day=31; break;}return day;}int month_cha(int x,int y){int day;switch(y){case 1: day=0; break;case 2: day=3; break;case 3: day=3+run(x); break;case 4: day=6+run(x); break;case 5: day=1+run(x); break;case 6: day=4+run(x); break;case 7: day=6+run(x); break;case 8: day=2+run(x); break;case 9: day=5+run(x); break;case 10: day=0+run(x); break;case 11: day=3+run(x); break;case 12: day=5+run(x); break;}day+=year_cha(x);if(day<0){day=7-(-day)%7;}if(day>6){day=day%7;}return day;}int year_cha(int x){int i,day=0;if(x>2012)for(i=2012;i<x;i++){day+=run(i);day++;}else if(x<2012)for(i=x;i<2012;i++){day=day-run(i);day--;}else day=0;printf("day=%d\n",day);return day;}}。
万年历c语言编程代码
#include <stdio.h>// 函数声明int is_leap_year(int year);int get_first_day_of_year(int year);// 主函数int main() {int year, month, first_day_of_year, first_day_of_month, days_in_month;int i, j, k;printf("请输入年份(例如:2022):");scanf("%d", &year);first_day_of_year = get_first_day_of_year(year);for (month = 1; month <= 12; month++) {printf("%d 年%d 月\n", year, month);printf("日一二三四五六\n");if (month == 2) {if (is_leap_year(year)) {days_in_month = 29;} else {days_in_month = 28;}} else if (month == 4 || month == 6 || month == 9 || month == 11) { days_in_month = 30;} else {days_in_month = 31;}first_day_of_month = (first_day_of_year + (month-1)*28)%7;for (i = 1; i <= first_day_of_month; i++) {printf(" ");}for (j = 1; j <= days_in_month; j++) {printf("%2d ", j);k = (i + j - 1) % 7;if (k == 0) {printf("\n");}}printf("\n");}}// 判断是否闰年int is_leap_year(int year) {return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);}// 计算年份第一天是星期几int get_first_day_of_year(int year) {int first_day = (year - 1) * 365 + (year - 1) / 4 - (year - 1) / 100 + (year - 1) / 400;first_day = (first_day + 1) % 7;return first_day;}这是一个简单的万年历示例代码,但它不是完整的代码。
C语言万年历代码
else if(ch=='n'||ch=='N')
{ month+=1;
if(month>12) {month=1;year+=1;}
}
printf("\t\t********e退出 p上一月 n下一月********");
}
void first_set(int *year,int *month)
{ do{
printf ("please input the year(1~9999):");
if (choose=='y'||choose=='Y') main();
}
days_of_month(int x,int y)
{
int z;
switch (y)
{case 1:
case 3:
case 5:
case 7:
case 8:
printf ("please input the month(1~12):");
scanf ("%d",month);
if(*month<1||*month>12) printf ("WANNING:ERROR,please input again!\n");
printf ("\n\n********************************************************************************\n\n");
自己做的日历(C语言)
本帖最后由 kekeyu 于 2010-8-15 16:59 编辑
C语言万年历程序
#include<stdio.h>#include<math.h>int fun(int a,int tianshu) //定义一个月份日期和星期几并显示的子函数{int i,k;{ for(i=0;i<a;i++) printf(""); //通过改变i和k的值改变循环次数和输出的日期for(i=a+1,k=1;i<tianshu+a;i++){ if(k<10) printf("%d ",k);else printf("%d ",k);k++;if(i%7==0) printf("\n");} //当i为7时,换行printf("\n");}a=(i-1)%7; //a为该月份结束时最后一个日期是星期几return a;}void shuchu(char a[8]) //定义一个显示月份和分割线的子函数{printf("----------------------------------------\n");printf("%s\n",&a[0]);printf("Sun Mon Tue Wed Thu Fri Sat\n");}void panduan(int dd,int yuefen,int ri,int year){int i,j=0,sum=0,k[]={31,29,31,30,31,30,31,31,30,31,30,31};int b;int a[]={31,28,31,30,31,30,31,31,30,31,30,31};if(year%4==0&&year%100!=0||year%400==0){for(i=1;i<yuefen;i++,j++)sum=sum+k[j];}else {for(i=1;i<yuefen;i++,j++)sum=sum+a[j];}sum=sum+ri;b=(sum+dd-1)%7;if(b==0) printf("\n%d年%d月%d日是星期日",year,yuefen,ri);if(b==1) printf("\n%d年%d月%d日是星期一",year,yuefen,ri);if(b==2) printf("\n%d年%d月%d日是星期二",year,yuefen,ri);if(b==3) printf("\n%d年%d月%d日是星期三",year,yuefen,ri);if(b==4) printf("\n%d年%d月%d日是星期四",year,yuefen,ri);if(b==5) printf("\n%d年%d月%d日是星期五",year,yuefen,ri);if(b==6) printf("\n%d年%d月%d日是星期六",year,yuefen,ri);}void main(){int year,month,i=0,j=0,k=1,a=0,m;int aa,bb,cc,dd;char n[]="Feb 2",b[]="Mar 3",c[]="Apr 4",d[]="May 5",e[]="Jun 6",f[7]="Jul 7",g[7]="Aug 8",h[7]="Sep 9",p[7]="Oct 10",q[7]="Nov 11",s[7]="Dec 12";printf("****************************************\n");printf("input the year:");scanf("%d",&year);shuruyue: printf("\ninput the month:");scanf("%d",&month);if(month>=13) goto error1;shururi:printf("\ninput the day:");scanf("%d",&aa);if(year%4==0&&year%100!=0||year%400==0){if(month==2&&aa>=30)goto error2 ;}else {if(month==2&&aa>=29)goto error2;}if(month==1&&aa>=32)goto error2 ;if(month==3&&aa>=32)goto error2 ;if(month==4&&aa>=31)goto error2 ;if(month==5&&aa>=32)goto error2 ;if(month==6&&aa>=31)goto error2 ;if(month==7&&aa>=32)goto error2 ;if(month==8&&aa>=32)goto error2 ;if(month==9&&aa>=31)goto error2 ;if(month==10&&aa>=32)goto error2 ;if(month==11&&aa>=31)goto error2 ;if(month==12&&aa>=32)goto error2 ;dd=(year+(year-1)/4-(year-1)/100+(year-1)/400)%7;panduan(dd,month,aa,year);printf("\n****************************************\n");printf("\nTHE CALENDER OF THE YEAR %d\n",year);printf("\n****************************************\n");printf("Jan 1\n");printf("Sun Mon Tue Wed Thu Fri Sat\n");dd=(year+(year-1)/4-(year-1)/100+(year-1)/400)%7; //判断该年的第一天是星期几a=fun(dd,32);shuchu(n);if(year%4==0&&year%100!=0||year%400==0) //判断该年是闰年还是平年a=fun(a,30);else a=fun(a,29);shuchu(b); //调用显示月份和分割线的函数a=fun(a,32); //调用显示月份全部排版的子函数shuchu(c);a=fun(a,31);shuchu(d);a=fun(a,32);shuchu(e);a=fun(a,31);shuchu(f);a=fun(a,32);shuchu(g);a=fun(a,32);shuchu(h);a=fun(a,31);shuchu(p);a=fun(a,32);shuchu(q);a=fun(a,31);shuchu(s);a=fun(a,32);goto jieshu;error1: printf("\nERROR INPUT MONTH.\n");printf("****************************************\n");printf("input the year:%d\n",year);goto shuruyue;error2: printf("\nERROR INPUT DAY.\n");printf("****************************************");printf("\ninput the year:%d\n",year);printf("\ninput the year:%d\n",month);goto shururi;jieshu:return 0;}。
新建 万年历c语言
#include"stdio.h"#include"stdlib.h"main( ){int Year,Month,Day; //年、月int FirstDay_Year,FirstDay_Month; //某年的第一天是星期几,某年某月的第一天是星期几(范围是0~6,其中0代表星期日)int IsLeapYear; //是否为闰年,0表示不是闰年,1表示是闰年int i,d,y,A,B,C,Y,M,D; //临时变量int riqi(int Year,int Month,int Day);//阳历转化为阴历的函数int yuefen(int Year,int Month,int Day);int nianfen(int Year,int Month,int Day);char YN; //Yes No,程序是否要继续int Days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};//Days[1~12]存储每个月有多少天,其中二月的天数是可变的(闰年29天,平年28天),这里初始化为28天printf(" 万年历\n"); //打印标题XunHuan: //循环标号(可以通过goto跳转到这里)printf("请输入年份: "); //提示输入年份(0~9999)scanf("%d",&Year); //把输入的年份赋值给变量Yearprintf("请输入月份: "); //提示输入月份(1~12)scanf("%d",&Month); //把输入的月份赋值给变量Monthprintf("请输入日期: "); //提示输入日期scanf("%d",&Day); //把输入的日期赋值给变量Dayy=Year;FirstDay_Year=5*(y/4)+(y%4)-(y/100)+(y/400);//蔡勒公式(计算某年的第一天是星期几) IsLeapYear=(((y%4==0&&y%100!=0)||y%400==0) && y!=0)?1:0;//判断是否为闰年Days[2]=(IsLeapYear==1)?29:28; //闰年二月29天,非闰年二月28天for(i=1,d=0;i<Month;i++)d=d+Days[i];FirstDay_Month=(d+FirstDay_Year)%7; //当月的第一天是星期几(0代表星期日)printf("\n**********************************************************\n");printf(" 公元%d 年%2d 月%2d日",Year,Month,Day); //打印年月A=nianfen(Year,Month,Day);B=yuefen(Year,Month,Day);C=riqi(Year,Month,Day);printf(" 农历%d 年%2d月%2d日",A,B,C);printf("\n**********************************************************\n");printf(" 星期日星期一星期二星期三星期四星期五星期六\n");//打印星期表头for(i=0;i<FirstDay_Month;i++)printf("%8c",' '); //当某月的第一天不是星期日时打印空格占位for(d=1;d<=Days[Month];d++) //循环,从每个月的第一天开始打印{if(d==Day){printf("%4c",' '); //显示被输入的日期if(Month==1&&Day==1){printf("\b\b元旦节");}else if(Month==2&&Day==14){printf("\b\b情人节");}else if(Month==3&&Day==8){printf("\b\b妇女节");}else if(Month==4&&Day==1){printf("\b\b愚人节");}else if(Month==4&&Day==5){printf("\b\b清明节");}else if(Month==5&&Day==1){printf("\b\b劳动节");}else if(Month==6&&Day==1){printf("\b\b儿童节");}else if(Month==8&&Day==1){printf("\b\b建军节");}else if(Month==10&&Day==1) {printf("\b\b国庆节");}else if(Month==10&&Day==5) {printf("\b\b教师节");}else{printf("[%2d]",d);}if(B==1&&C==1){printf("\b\b\b\b春节");}else if(B==1&&C==5){printf("\b\b\b\b\b\b元宵节"); }else if(B==5&&C==5){printf("\b\b\b\b\b\b端午节"); }else if(B==7&&C==7){printf("\b\b\b\b\b\b乞巧节"); }else if(B==8&&C==15){printf("\b\b\b\b\b\b中秋节"); }else if(B==9&&C==9){printf("\b\b\b\b\b\b重阳节"); }else if(B==12&&C==8){printf("\b\b\b\b\b\b腊八节"); }}else{printf("%6c",' ');printf("%2d",d);}if(((d+FirstDay_Month)%7)==0 && d<Days[Month])printf("\n"); //当输出了星期六而且还未输出所有天数时,换行}printf("\n**********************************************************\n"); printf("\n");printf("是否继续(Y/N)?\n");scanf("%c",&YN);scanf("%c",&YN);if(YN=='Y' || YN=='y')goto XunHuan;}int riqi(int Year,int Month,int Day){int q,r,t,i,a,s=0;int IsLeapYear;int Days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};IsLeapYear=(((Year%4==0&&Year%100!=0)||Year%400==0) && Year!=0)?1:0;Days[2]=(IsLeapYear==1)?29:28;q=(Year-1977)/4;r=(Year-1977)-4*q;for(i=0;i<Month;i++){s=s+Days[i];}t=(int)(14*q+10.6*(r+1)+s+Day)/29.5;a=(int)((14*q+10.6*(r+1)+s+Day)-t*29.5);while(Month==1){Year--;Month=Month+12;}Month=Month-1;return a;}int yuefen(int Year,int Month,int Day){int q,r,t,i,a,s=0;int Days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};q=(Year-1977)/4;r=(Year-1977)-4*q;for(i=1;i<Month;i++){s=s+Days[i];}t=(int)(14*q+10.6*(r+1)+s+Day)/29.5;a=(int)(14*q+10.6*(r+1)+s+Day)-t*29.5;while(Month==1){if(Day<23){Year=Year-1;Month=Month+12;}else{Month=Month+1;} }Month=Month-1;return Month;}int nianfen(int Year,int Month,int Day){int q,r,t,i,a,s=0;int Days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};q=(Year-1977)/4;r=(Year-1977)-4*q;for(i=1;i<Month;i++){s=s+Days[i];}t=(int)(14*q+10.6*(r+1)+s+Day)/29.5;a=(int)(14*q+10.6*(r+1)+s+Day)-t*29.5;while(Month==1&&Day<25){Year--;Month=Month+12;}Month=Month-1;return Year;}。
用c语言编写万年历
#include<stdio.h>//假设今天是2013年12月22号,是星期天,根据这个日期计算日历中的某天距离今天有多少天,且输入的日期为星期几!查表得1800年1月1日为星期三。
int i,j,k,a,b,c,w=0;//i,j,k分别代表全局变量的年月日。
int y(){int p, h=0,inleap=0,leap=0,sum=0,count1,count2,leap1;scanf("%d",&i);if(i>2100||i<1800)printf("输入的年份不合法,或者不在程序运算的范围内");else{ printf("%d年的年历为:\n",i);for(j=1;j<=12;j++){{for(a=1800;a<=i;a++){if((a%4==0&&a%100!=0)||(a%400==0))leap++;else inleap++;}count1=leap*366;count2=inleap*365;switch(j){case 1:sum=0;break;case 2:sum=31;break;case 3:sum=59;break;case 4:sum=90;break;case 5:sum=120;break;case 6:sum=151;break;case 7:sum=181;break;case 8:sum=212;break;case 9:sum=243;break;case 10:sum=273;break;case 11:sum=304;break;case 12:sum=334;break;}sum=sum+count1+count2;{if(i%400==0||(i%4==0&&i%100!=0))leap1=1; //如果不是闰年则直接执行elseleap1=0;if(leap1==1&&j>2) //如果是闰年并且月份大于2,总天数应该加一天sum++;}h=(sum+2)%7;}if((i%4==0&&i%100!=0)||(i%400==0)){switch(j){case 1:case 3:case 5:case 7:case 8:case 10:case 12:printf("\t\t%d月\n",j);printf("%4s%4s%4s%4s%4s%4s%4s\n","Sun","Mon","Tues","Wed","Thur","Fri","Sat");for(p=0;p<h;p++)printf(" ");for(c=1;c<=31;c++){printf("%4d",c);if((c+h)%7==0)printf("\n");}printf("\n");break;case 4:case 6:case 9:case 11:printf("\t\t%d月\n",j);printf("%4s%4s%4s%4s%4s%4s%4s\n","Sun","Mon","Tues","Wed","Thur","Fri","Sat");for(p=0;p<h;p++)printf(" ");for(c=1;c<=30;c++){printf("%4d",c);if((h+c)%7==0)printf("\n");}printf("\n");break;case 2:printf("\t\t%d月\n",j);printf("%4s%4s%4s%4s%4s%4s%4s\n","Sun","Mon","Tues","Wed","Thur","Fri","Sat");for(c=1;c<=29;c++){printf("%4d",c);if((c+h)%7==0)printf("\n");}printf("\n");}}else{switch(j){case 1:case 3:case 5:case 7:case 8:case 10:case 12:printf("\t\t%d月\n",j);printf("%4s%4s%4s%4s%4s%4s%4s\n","Sun","Mon","Tues","Wed","Thur","Fri","Sat");for(p=0;p<h;p++)printf(" ");for(c=1;c<=31;c++){printf("%4d",c);if((c+h)%7==0)printf("\n");}printf("\n");break;case 4:case 6:case 9:case 11:printf("\t\t%d月\n",j);printf("%4s%4s%4s%4s%4s%4s%4s\n","Sun","Mon","Tues","Wed","Thur","Fri","Sat");for(p=0;p<h;p++)printf(" ");for(c=1;c<=30;c++){printf("%4d",c);if((h+c)%7==0)printf("\n");}printf("\n");break;case 2:printf("%4s%4s%4s%4s%4s%4s%4s\n","Sun","Mon","Tues","Wed","Thur","Fri","Sat");printf("\t\t%d月\n",j);for(p=0;p<h;p++)printf(" ");for(c=1;c<=28;c++){printf("%4d",c);if((c+h)%7==0)printf("\n");}printf("\n");break;}}}}}int ym(){int p,h=0,inleap=0,leap=0,count,sum=0,count1,count2,leap1;scanf("%d%d",&i,&j);if(i<1800||i>2100||j<1||j>12)printf("您输入的年月份不在运算范围或者不合法,请重新输入!");else{ printf("%d年%d月的月历为:\n",i,j);{for(a=1800;a<i;a++){if((a%4==0&&a%100!=0)||(a%400==0))leap++;else inleap++;}count1=leap*366;count2=inleap*365;switch(j){case 1:sum=0;break;case 2:sum=31;break;case 3:sum=59;break;case 4:sum=90;break;case 5:sum=120;break;case 6:sum=151;break;case 7:sum=181;break;case 8:sum=212;break;case 9:sum=243;break;case 10:sum=273;break;case 11:sum=304;break;case 12:sum=334;break;}sum=sum+count1+count2;{if(i%400==0||(i%4==0&&i%100!=0))leap1=1; //如果不是闰年则直接执行elseleap1=0;if(leap==1&&j>2) //如果是闰年并且月份大于2,总天数应该加一天sum++;}h=(sum+3)%7;}if((i%4==0&&i%100!=0)||(i%400==0)){switch(j){case 1:case 3:case 5:case 7:case 8:case 10:case 12:printf("\t\t%d月\n",j);printf("%4s%4s%4s%4s%4s%4s%4s\n","Sun","Mon","Tues","Wed","Thur","Fri","Sat");for(p=0;p<h;p++)printf(" ");for(c=1;c<=31;c++){printf("%4d",c);if((c+h)%7==0)printf("\n");}printf("\n");break;case 4:case 6:case 9:case 11:printf("\t\t%d月\n",j);printf("%4s%4s%4s%4s%4s%4s%4s\n","Sun","Mon","Tues","Wed","Thur","Fri","Sat");for(p=0;p<h;p++)printf(" ");for(c=1;c<=30;c++){printf("%4d",c);if((h+c)%7==0)printf("\n");}printf("\n");break;case 2:printf("\t\t%d月\n",j);printf("%4s%4s%4s%4s%4s%4s%4s\n","Sun","Mon","Tues","Wed","Thur","Fri","Sat");for(c=1;c<=29;c++){printf("%4d",c);if((c+h)%7==0)printf("\n");}printf("\n");break;}}else{switch(j){case 1:case 3:case 5:case 7:case 8:case 10:case 12:printf("%4s%4s%4s%4s%4s%4s%4s\n","Sun","Mon","Tues","Wed","Thur","Fri","Sat");printf("\t\t%d月\n",j);for(p=0;p<h;p++)printf(" ");for(c=1;c<=31;c++){printf("%4d",c);if((c+h)%7==0)printf("\n");}printf("\n");break;case 4:case 6:case 9:case 11:printf("%4s%4s%4s%4s%4s%4s%4s\n","Sun","Mon","Tues","Wed","Thur","Fri","Sat");printf("\t\t%d月\n",j);for(p=0;p<h;p++)printf(" ");for(c=1;c<=30;c++){printf("%4d",c);if((h+c)%7==0)printf("\n");}printf("\n");break;case 2:printf("%4s%4s%4s%4s%4s%4s%4s\n","Sun","Mon","Tues","Wed","Thur","Fri","Sat");printf("\t\t%d月\n",j);for(p=0;p<h;p++)printf(" ");for(c=1;c<=28;c++){printf("%4d",c);if((c+h)%7==0)printf("\n");}printf("\n");}}}}int ymd(){int sum=0,leap=0,inleap=-1,leap1,count1=1,count2=1,count3=356,count4,count;//其中的lead代表是从当年到今年的闰年数,count1则为闰年的总天数,//inlead代表的是从当年日期到今年的日期的平年数,count2则为平年的总天数,count3则为今年的第N天,count4则为当年的倒数第N天。
C语言-万年历
}
week=(year-1)*365+(year-1)/4-(year-1)/100+(year-1)/400+d;//判断这个月的第一天是星期几
week=week%7;
printf("\n\n\t这是%d年的%d月的日历\n",year,month);
Today(year,month,day);
Tomonth(year,month);
printf("\n\t\t输 入 Y 或 者 y 键 继 续。。。");
for(;getch()=='y'||getch()=='Y';)
{
printf("\n\n 请 输 入 您 所 想 要 的 功 能:\n");
scanf("%d",&x);
switch(x)
{
case 1:
{
system("cls");
search();
printf("\n\t\t 按 Y 或 者 y 继 续 ...");
break;
}
case 2:
{
system("cls");
case 3:printf("\t%d 年%d 月%d 日 是 星 期: 三",year,month,day);break;
case 4:printf("\t%d 年%d 月%d 日 是 星 期: 四",year,month,day);break;
case 5:printf("\t%d 年%d 月%d 日 是 星 期: 五",year,month,day);break;
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
《C程序设计》课程设计报告2011-2012学年第二学期设计题目:万年历的设计指导教师:李素若完成时间:2012年6月1日至2011年6月26日第 1 组报告成员成绩评定:分任课教师签字: 2012年6月 21 日目录目录目录 (2)1序言 (3)2设计题目 (3)3问题定义 (4)4总体分析与设计 (5)4.1总体流程图 (5)4.2算法中涉及的知识点 (6)4.3详细设计 (6)5调试与测试 (9)6参考文献 (11)7总结与心得 (11)1 序言我们经过了一个学期的c语言课程的学习,对计算机变成所需的c语言有了大体的了解,能够看懂和编写一些简单的c语言程序,为了更好的加深同学们对c语言的认识,提升同学们的c语言时间编程能力,所以进行了c语言的课程设计。
本程序是一个万年历程序,可以在程序中任意的输入公元年份,通过程序的将该年份的各种信息形象直观的显示出来,达到c语言程序编写所体现的方便快捷的功效。
同时,通过对该程序c语言的编写,能够在训炼我们在课本中学到各种知识点,并将其应用其中。
2 设计题目:1设计编写一个C程序—“万年历”。
2输入任一年将显示出该年的所有月份日期,对应的星期。
3 下一行显示星期,从周日到周六,中英文都可以。
4 下一行开始显示日期从1号开始,并按其是周几实际情况与上面的星期数垂直对齐。
5 月份:中文英文都可以,注意闰年情况。
3 问题定义(或系统分析):1 要输入任一年显示出该年的所有月份日期,应该先设计具体的输出格式,如下:the calendar of the year2008.JanuarySun Mon Tue Wed Thu Fri Sat1 2 3 4 56 7 8 9 10 11 1213 14 15 16 17 18 1920 21 22 23 24 25 2627 28 29 30 31FebruarySun Mon Tue Wed Thu Fri Sat1 23 4 5 6 7 8 910 11 12 13 14 15 1617 18 19 20 21 22 2324 25 26 27 28 29=============================================2 判断是不是闰年(year%4!=0||year%100==0&&year%400!=0)满足条件就是平年,把一年中的所有月份分为四类(28,29,30,31)。
3 求出一年中的第一天是周几(year +(year-1)/4-(year-1)/100+(year-1)/400)%7。
4 有指针数组存放十二个月的英文和星期的英文缩写。
5 用FOR循环输出各月份的日历4 总体设计与详细设计:4.1 总体流程图4.2 算法中涉及的知识点1 定义整型,字符型,指针变量,字符型数组和指针数组。
数组的初始化和引用和指针的使用。
2 函数的定义、声名、调用以及函数的返回值。
3 程序的三种基本结构:顺序,选择,循环。
if语句的嵌套,for语句的嵌套。
4 赋值语句的使用。
5 输入(scanf)输出(printf)函数的应用。
6 算术运算符、关系运算符和逻辑运算符的应用.4.3 详细设计:#include<stdio.h>int judge(int year,int month){if(month==1||month==3||month==5||month==7||month==8||mon th==10||month==12)return(1);else if(month==2){if(year%4!=0||year%100==0&&year%400!=0)return(2);else return(3);}else return(4);}int main(){int year,i,j,a,n,m,k;char ** p;char * week[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};char*month[]={"January","February","March","April","May" ,"June","July","August","September","October","November","D ecember"};printf("please inter the year:");scanf("%d",&year);printf("\n");printf("the calendar of the year%d.",year);printf("\n");a=((year-1)*365+(year-1)/4-(year-1)/100+(year-1)/400+1)%7; for(i=0;i<12;i++){n=judge(year,i+1);p=month+i;printf("%s\n",*p);printf("\n");for(j=0;j<7;j++){p=week+j;printf("%6s",*p);}printf("\n");for(k=0;k<a;k++)printf(" ");for(m=1;m<32;m++){printf("%6d",m);if((a+m)%7==0)printf("\n");if(n==1&&m==31) break;else if(n==2&&m==28) break;else if(n==3&&m==29) break;else if(n==4&&m==30) break;}a=(a+m)%7;printf("\n");printf("============================================");printf("\n");}}5 调试与测试:1.登陆界面图4-1登陆界面提供了四个选项进行选择,并提示输入后的操作方法;2.显示某年全年日历图4-2输入指令后,依次打印出每个月份的日历。
并显示平年或者闰年;3.显示某月日历5 参考文献[1]谭浩强著《C语言程序设计》北京:清华大学出版社 2005[2]百度知道6 总结与心得:1.C语言是目前流行的计算机日历程序,比较典型的是Windows各版本中的日历程序以及基础于该程序所开发的各种应用程序中的日历程序。
然而,这些程序都千篇一律的局限在一个很短的时间范围内。
但是,在很多情况下,特别是在众多的科学研究领域中,一个时间跨度较大的日历程序是很有参考价值的。
C程序设计语言充分发挥了其自身无与伦比的优越性,用极短的程序文本填补了这一领域的空白,同时用铁的事实强有力的告诉世人:C程序设计语言作为计算机语言家族的新生事物,其发展前景是极为广阔的。
2. 经过上一个学期对《C程序设计》的学习,我们学习了理论知识,了解了C语言程序设计的思想,这些知识都为我们的下一步学习打下了坚实的基础。
通过课程设计,一方面是为了检查我们一个学期来我们学习的成果,另一方面也是为了让我们进一步的掌握和运用它,同时也让我们认清自己的不足之处和薄弱环节,加以弥补和加强。
3. 通过对c语言万年历的设计进一步的巩固了用c语言编写程序,并且有利于更好的掌握c语言!4. 在万年历的编写过程中也体会到了做事情一顶要细心、认真。
更加知道了要掌握好基础知识。
还有体会到了成功的感觉!在万年历的设计过程中更加体会到了团队合作的重要性,知道了只有团队合作才会更好的完成设计!也体会到以后在工作中团队合作的必要性和重要性!5. 通过本项课程设计也培养了我独立思考、综合运用所学有关相应知识的能力,掌握工程软件设计的基本方法,强化上机动手编程能力,闯过理论与实践相结合的难关!6. 由于C语言是近年在国内外得到迅速推广应用的一种语言。
C语言功能丰富,表达能力强,使用灵活方便,应用面广,目标程序效率高,可移植性好,既具有高级语言的优点,又具有低级语言的许多特点。
通过这次的c语言程序设计更加了解了c语言的好处和其可用性!7. 在这次课程设计中也知道了自己的动手能力不强有待进一部的提高!在设计过程中不能够把书本上的知识与实践相结合,这也就增加了设计不好该程序的想法!在设计过程中的一次次设计错误增加了我放弃的想法!不过经过大家的努力终于完成了课程设计!完成该程序后想起自己以前的每一次对自己失去信心,就觉得并不是在知识掌握上打败了,而是自己对自己缺乏信心!只要自己对自己不失去信心相信就可以完成那些以前认为完成不了的事情!也让我懂得了要想成功首先就必须有很强的自信心!懂得了自己以后要在做任何事情时都要自信!通过本次课程设计我第一次通过自己的实践对书本上的知识进行了与生活相关的运用,使我受益匪浅,我将不断地学习c语言知识,不断完善自己,提升自己对c语言的理解力。