简易万年历(C++语言程序代码)
C语言编写的万年历代码
该代码在VC++6.0编译器下运行,只要按照编译器给出的说明操作,就能将万年历显示在调试窗口中了……………………………………由于制作时间匆忙,很多注释都来不及写了,对于出学者可以慢慢看,代码很简单的,都放在了主函数里,如果有兴趣的话,可以把这些代码放在几个文件里,这样会好看点,加油了!#include<stdio.h>#include<math.h>void main(){int m,i,j,n=0,y=2010,wo,w,a;printf("input the form of: year-month:\t");scanf("%d-%d",&y,&m); //输入格式的决定if(y%4==0&&y%100!=0||y%400==0)a=29;else a=28; //闰年的判断及2月日数的确定if(m<1||m>12){printf("month is not exit,please input later!\n");exit(0);}wo=(y+(y-1)/4-(y-1)/100+(y-1)/400)%7; //1月1日的算法wo表示for(i=0;i<55;i++)printf("*"); //*的输入printf("\n");for(j=1;j<=7;j++)printf("星期%d\t",j); //星期的输入printf("\n"); //表前的建造switch(m){case 1:for(i=1;i<wo;i++){printf("\t");n++;}for(j=1;j<=31;j++){if(n%7==0)printf("\n");printf("%d\t",j);n++;}break; // 1 month case 2:w=(wo+31)%7;for(i=1;i<w;i++){printf("\t");n++;}for(j=1;j<=a;j++){if(n%7==0)printf("\n");printf("%d\t",j);n++;}break; // 2 month case 3:w=(wo+31+a)%7;for(i=1;i<w;i++){printf("\t");n++;}for(j=1;j<=31;j++){if(n%7==0)printf("\n");printf("%d\t",j);n++;}break; // 3 month case 4:w=(wo+31+a+31)%7;for(i=1;i<w;i++){printf("\t");n++;}for(j=1;j<=30;j++){if(n%7==0)printf("\n");printf("%d\t",j);n++;}break; // 4 monthcase 5:w=(wo+31+a+31+30)%7;for(i=1;i<w;i++){printf("\t");n++;}for(j=1;j<=31;j++){if(n%7==0)printf("\n");printf("%d\t",j);n++;}break; // 5 monthcase 6:w=(wo+31+a+31+30+31)%7;for(i=1;i<w;i++){printf("\t");n++;}for(j=1;j<=30;j++){if(n%7==0)printf("\n");printf("%d\t",j);n++;}break; // 6 monthcase 7:w=(wo+31+a+31+30+31+30)%7;for(i=1;i<w;i++){printf("\t");n++;}for(j=1;j<=31;j++){if(n%7==0)printf("\n");printf("%d\t",j);n++;}break; // 7 monthcase 8:w=(wo+31+a+31+30+31+30+31)%7;for(i=1;i<w;i++){printf("\t");n++;}for(j=1;j<=31;j++){printf("\n");printf("%d\t",j);n++;}break; // 8 monthcase 9:w=(wo+31+a+31+30+31+30+31+31)%7;for(i=1;i<w;i++){printf("\t");n++;}for(j=1;j<=30;j++){if(n%7==0)printf("\n");printf("%d\t",j);n++;}break; // 9 monthcase 10:w=(wo+31+a+31+30+31+30+31+31+30)%7;for(i=1;i<w;i++){printf("\t");n++;}for(j=1;j<=31;j++){if(n%7==0)printf("\n");printf("%d\t",j);n++;}break; // 10 monthcase 11:w=(wo+31+a+31+30+31+30+31+31+30+31)%7;for(i=1;i<w;i++){printf("\t");n++;}for(j=1;j<=30;j++){if(n%7==0)printf("\n");printf("%d\t",j);n++;}break; // 11 monthcase 12:w=(wo+31+a+31+30+31+30+31+31+30+31+30)%7;for(i=1;i<w;i++){n++;}for(j=1;j<=31;j++){if(n%7==0)printf("\n");printf("%d\t",j);n++;}break; // 12 month}printf("\n");for(i=0;i<55;i++)printf("*");printf("\n"); //表尾的处理}。
用C语言编写的万年历
// VC++6.0 编译通过# include <stdio.h># include <windows.h>int year; //定义年份为全局变量int check_year (int year) //判断输入的年份是否为闰年{if(year%4 == 0 && year%100 !=0 || year%400 == 0)return 1;elsereturn 0;}int check_month (int month) //判断每月的天数{switch (month){case 0: return 0; break;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 (check_year(year) == 1)return 29;elsereturn 28;} break;}}int firstday (int year,int month) //判断某年某月的第一天为星期几{static int w=0;w += check_month(month-1);return ((year-1)+((year-1)/4)-((year-1)/100)+((year-1)/400)+1+w)%7;}main (){int month=1,day,i,flag;printf ("请输入要打印的年份: ");scanf ("%d",&year);printf ("\n");printf (" %d年\n\n",year);for (month=1;month<=12;month++){printf (" %d月\n",month);printf (" ---------------------------\n");printf (" SUN MON TUE WED THU FRI SET\n");printf (" ---------------------------\n");flag = firstday(year,month);for (i=0;i<flag;i++) //每月第一天所在星期几之前的位置用空格输出printf (" ");for (day=1;day<=check_month(month);day++) //按格式输出日历{printf ("%4d",day);if ((day+flag)%7 == 0)printf ("\n");}printf("\n\n");system("pause");printf("\n");}}。
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#include#include#include#include# define YEAR 365int numday[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31}, {31,29,31,30,31,30,31,31,30,31,30,31}};int leap(int year);int calday(int y,int m);int counterdays(int year,int month,int day);int week(int year,int month,int day);int eachyeartotal(int year,int month,int day);int maxDay(int y,int month);void print(int y,int m,int w);void festival (int year,int month,int day);int IsLeap(int y);int guanli(int i);void rili(int year,int month);int rili1();void rili2();void rili3();void rili4();void rili5();void fan();void show(int year,int month,int date,int sec,int mini,int hour);int main(){int i;printf("***************************************\n"); printf("1.查询日历,输入年份:\n");printf("2.查询该月日历及对应星期,输入年份和月份:\n"); printf("3.查询星期几及节日,输入年月日:\n");printf("4.距您输入日期还有多少天,输入日期:\n"); printf("5.通过键盘上下控制不同年月日:\n");scanf("%d",&i);guanli(i);return 0;}int guanli(int i){switch(i){case 1:rili1();return main();case 2:rili2();return main();case 3:rili3();return main();case 4:rili4();return main();case 5:rili5();return main();}return 0;}int rili1(){int year;int n,i;printf("输入年份:");scanf("%d",&year);printf("the calendar of the year%d\n",year);printf("\n");printf("=============================\n"); for(i=1;i<13;i++){printf(" %d月份\n",i);rili(year,i);}n = leap(year);return 0;}void rili2(){int year,month,w;printf("输入年月:");scanf("%d%d",&year,&month);w=calday(year,month);print(year,month,w);}void rili3(){int year,month,day,number;printf("输入年月日:");scanf("%d%d%d",&year,&month,&day);festival(year,month,day);number= week(year,month,day);printf("星期%d",number);}void rili4(){int year,month,day;printf("输入年月日:");scanf("%d%d%d",&year,&month,&day); eachyeartotal( year,month,day);counterdays(year,month,day);}void rili5(){int year,month,date,sec,mini,hour;fan();show(year,month,date,sec,mini,hour);}int leap(int year){int n=(year%4==0 && year%100!=0 || year%100!=0); return n;}void rili(int year,int month){int i,day,first_day,flag,year1,year2;int temp = 6;flag =leap(year);year1=year/100;year2=year%100;if(year>2000){year1=year1-20;day = year1/4;day+=(YEAR+24)*year1+YEAR*year2+(year2-1)/4;if(year>2000)day++;switch(month){case 1:day; break;case 2:day+=31;break;case 3:day+=59+flag;break;case 4:day+=90+flag;break;case 5:day+=120+flag;break;case 6:day+=151+flag;break;case 7:day+=181+flag;break;case 8:day+=212+flag;break;case 9:day+=243+flag;break;case 10:day+=273+flag;break;case 11:day+=304+flag;break;case 12:day+=334+flag;break;}day+=temp;first_day=day%7;}else{year1 = 20-1-year;year2=100-year2-1;day+=(YEAR+24)*year1+YEAR*year2+year2/4; switch(month){case 12:day+=31;break;case 11:day+=61;break;case 10:day+=92;break;case 9:day+=122;break;case 8:day+=153;break;case 7:day+=184;break; case 6:day+=214;break; case 5:day+=245;break; case 4:day+=275;break; case 3:day+=306;break; case 2:day+=334+flag;break; case 1:day+=365+flag;break; }day-=temp;day = day%7;first_day=(7-day)%7;}switch(month){case 1:case 2:month=28+flag;break; case 3:case 4:case 5:case 6:case 7:case 8:case 9:case 10:case 11:month=30;break; case 12:month =31;break;}for(i=1;i<4*first_day;i++) printf(" ");for(i=0;i<month;i++)< p="">{printf("%4d",i+1);if((first_day+i)%7==6)printf("\n");}printf("\n");printf("===============================\n");}///////////////////////////////////////////////////////////int counterdays(int year,int month,int day){int year1,days0,days1,month1,days,day1;time_t timep;struct tm*p;time(&timep);p=gmtime(&timep);year1=(1900+p->tm_year);month1=(1+p->tm_mon);day1=(p->tm_mday);days0=(year-1)*365 + (year-1)/4 - (year-1)/100 + (year-1)/400 +eachyeartotal (year,month,day);days1=(year1 - 1)*365+(year1-1)/4-(year1-1)/100 + (year1 - 1)/400 +eachyeartotal (year1,month1,day1);days=days0-days1;printf("\n今天距%d年%d月%d日还有%d天\n\n",year,month,day,days);return days;}int eachyeartotal(int year,int month,int day){int i,sum=0;for(i=1;i<month;i++)< p="">{sum+=maxDay(year,i);}sum+=day;return sum;}int IsLeap(int y){if(y%4==0 && y%100!=0 || y%400==0) return 1; else return 0;}int maxDay(int y,int month){int a[12]={31,28,31,30,31,30,31,31,30,31,30,31};if(IsLeap(y))a[1]=29;return a[month-1];}///////////////////////////////////////void festival (int year,int month,int day){if (month==1 && day==1) printf (",这天是元旦");if (month==2 && day==14) printf (",这天是情人节"); if (month == 3)switch(day){case 8:printf (",这天是妇女节"); break;case 12:printf (",这天是植树节");}if (month==1 && day==1) printf (",这天是愚人节");if(month == 5)switch (day){case 1:printf(",这天是劳动节");break;case 4:printf(",这天是青年节");}if (month==6 && day==1) printf (",这天是儿童节");if (month==7 && day==1) printf (",这天是建党节");if (month==8 && day==1) printf (",这天是建军节");if (month==9 && day==10) printf (",这天是教师节");if (month==10 && day==1) printf (",这天是国庆节");printf("\n");}int week(int year,int month,int day){int number = (year-1)+(year-1)/4 - (year-1)/100+(year-1)/400+eachyeartotal(year,month,day);number = number%7;return number;}/////////////////////////////////////////////void print(int y,int m,int w){int i,l;printf("Calendar %d-%02d\n",y,m);printf("---------------------\n");printf("Su Mo Tu We Th Fr Sa \n");printf("---------------------\n");for (i=0;i<w;i++)< p=""> printf(" ");if (IsLeap(y))l=1;elsel=0;for (i=1;i<=numday[l][m-1];i++) {printf("%-3d",i);w++;if (w%7==0)printf("\n");}if (w%7) printf("\n");printf("---------------------\n"); }int calday(int y,int m){int d=0,w;while (y>1910){if (IsLeap(y)) d+=366;else d+=365;y--;}while (m>1){ --m;d+=numday[0][m-1];}w=(d+1)%7;return w;}//////////////////////////////////////////void show(int year,int month,int date,int sec,int mini,int hour) {const char month_str[][4]={"","Jan","Feb","Mar","Apl", "May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};const int month_day[]={0,31,28,31,30,31,30,31,31,30,31,30,31};int i,j,wdays,mdays,days;for(i=1,days=0;i<year;i++)< p="">{if(leap(i))days += 366;}else{days += 365;}}for(i=1;i<month;i++)< p="">{if(i==2 && leap(year)){days+=29;}else{days+=month_day[i];}}printf(" %s.%d.%d %d:%d:%d \n",month_str[month],date,year,hour,mini,sec);printf(" 一二三四五六日\n");wdays = days % 7;for( j = 0; j < wdays; j++){printf(" ");}if(month == 2 && leap(year)){mdays=29;}else{mdays= month_day[month];}for(i=1;i<=mdays;i++){if( i > 1 && days % 7 == 0 ){printf("\n");}printf("%4d",i);days=days+1; }printf("\n---------------------------\n\n\n");}{time_t rawtime;struct tm *info;int year,month,date,sec,mini,hour; char ch;time ( &rawtime );info = localtime ( &rawtime );year =info->tm_year + 1900; month =info->tm_mon + 1;date =info->tm_mday;hour =info->tm_hour;mini =info->tm_min;sec =info->tm_sec;while(1){show(year,month,date,sec,mini,hour); printf("↑......上一年\n\n");printf("↓......下一年\n\n");printf("←....前一个月\n\n");pr intf("→....后一个月\n\n");printf("Esc.......退出\n\n");ch=getch();switch(ch){case 27://Ecs exit(0);case -32://Navigatorch=getch();if(ch==77){//Rightyear+=(month==12)?1:0;month=month%12+1;}else if(ch==75){year-=(month==1)?1:0; month=(month-2+12)%12+1; }else if(ch==72)year--;else if(ch==80)year++;system("cls");}}</month;i++)<></year;i++)<></w;i++)<></month;i++)<></month;i++)<>。
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语言-万年历
#include <stdio.h>#include<time.h> //调用当前时间的头文件#include <stdlib.h>//调用清屏函数的头文件//这是一个万年历的c程序。
void Today(int year,int month,int day)//输出是星期几的函数。
{int d=0,i;int week;int a[12]={31,29,31,30,31,30,31,31,30,31,30,31};int b[12]={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<month;i++)d=d+a[i-1];}else{for(i=1;i<month;i++)d=d+b[i-1];}d=d+day;week=(year-1)*365+(year-1)/4-(year-1)/100+(year-1)/400+d;//判断这一天是星期几的公式。
week=week%7;//判断这一天是星期几的公式。
当week=0,表示星期日。
//下面是输出星期。
switch(week){case 1:printf("\t%d 年%d 月%d 日是星期: 一",year,month,day);break;case 2:printf("\t%d 年%d 月%d 日是星期: 二",year,month,day);break;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;case 6:printf("\t%d 年%d 月%d 日是星期: 六",year,month,day);break;case 0:printf("\t%d 年%d 月%d 日是星期: 日",year,month,day);break;}printf("\n\n");}void Tomonth(int year,int month)//输入日历的函数{int week;int t=1;int d=0,i;int a[12]={31,29,31,30,31,30,31,31,30,31,30,31};int b[12]={31,28,31,30,31,30,31,31,30,31,30,31};//这个if和for是计算d的值,d表示到今天为止总共的天数。
万年历程序设计c语言代码
这是当时我做的一个小小的课题,希望对你有所帮助#include "stdio.h" /* Required for MS-DOS use */#define ENTER 0x1C0D /* Enter key */int year, month, day;static char *days[8] = {" ","Sunday ","Monday ","Tuesday ","Wednesday","Thursday ","Friday ","Saturday "}; struct TIMEDATE {int year; /* year 1980..2099 */int month; /* month 1=Jan 2=Feb, etc. */int day; /* day of month 0..31 */int hours; /* hour 0..23 */int minutes; /* minute 0..59 */int seconds; /* second 0..59 */int hsecs; /* 1/100ths of second 0..99 */char dateline[47]; /* date & time together */};static struct TIMEDATE today;main(){char cmonth[3];char cday[3];char cyear[5];double getdays();double daynumb, numbnow;int weekday, retcode, dayer, i;dayer = datetime(&today);clrscn();for (i=0;i<3;++i)cmonth[i]='\0';for (i=0;i<3;++i)cday[i]='\0';for (i=0;i<5;++i)cyear[i]='\0';putstr(5,8,14,"Enter date in MM DD YYYY format:");while (retcode != ENTER){retcode = bufinp(5,41,13,2,cmonth);if (retcode != ENTER) retcode = bufinp(5,44,13,2,cday);if (retcode != ENTER) retcode = bufinp(5,47,13,4,cyear);}year = atoi(&cyear);month = atoi(&cmonth);day = atoi(&cday);daynumb = getdays(year, month, day);numbnow = getdays(today.year, today.month, today.day); weekday = weekdays(daynumb);if (numbnow - daynumb == 0)printf("\n\n%02d-%02d-%d is",month, day, year);if (numbnow - daynumb > 0)printf("\n\n%02d-%02d-%d was",month, day, year);if (numbnow - daynumb < 0)printf("\n\n%02d-%02d-%d will be",month, day, year);printf(" a %s\n",days[weekday]);} /* end MAIN *//************************************************************* GETDAYS - From integer values of year (YYYY), month * * (MM) and day (DD) this subroutine returns a ** double float number which represents the * * number of days since Jan 1, 1980 (day 1). * * This routine is the opposite of GETDATE. * ************************************************************/double getdays(year, month, day)int year, month, day;{int y,m;double a,b,d, daynumb;double floor(),intg();/************************************ make correction for no year 0 ************************************/if (year < 0) y = year + 1;else y = year;/*********************************************************** Jan and Feb are months 13 and 14 in this calculation ***********************************************************/m = month;if (month < 3){m = m + 12;y = y - 1;}/**************************** calculate Julian days ****************************/d = floor(365.25 * y) + intg(30.6001 * (m + 1)) + day - 723244.0;/************************************************ use Julian calendar if before Oct 5, 1582 ************************************************/if (d < -145068.0) daynumb = d;/*************************************** otherwise use Gregorian calendar ***************************************/else{a = floor(y / 100.0);b = 2 - a + floor(a / 4.0);daynumb = d + b;}return(daynumb);} /* end GETDAYS *//********************************************************* GETDATE - This routine takes a double float number * * representing the number of days since Jan 1,* * 1980 (day 1) and returns the year month and * * day as pointer integers * * This routine is the opposite of GETDAYS * ********************************************************/getdate(numb)double numb;{double a,aa,b,c,d,e,z;double date;date = numb;z = intg(date + 2444239.0);if (date < -145078.0) a = z;else{aa = floor((z - 1867216.25) / 36524.25);a = z + 1 + aa - floor(aa/4.0);}b = a + 1524.0;c = intg((b - 122.1) / 365.25);d = intg(365.25 * c);e = intg((b - d) / 30.6001);day = b - d - intg(30.6001 * e);if (e > 13.5) month = e - 13.0;else month = e - 1.0;if (month > 2) year = c - 4716.0;else year = c - 4715.0;if (year < 1) --year;return;} /* end GETDATE *//********************************************************* WEEKDAYS - This routine takes a double float number * * representing the number of days since Jan 1,** 1980 (day 1) and returns the day of the week** where 1 = Sunday, 2 = Tuesday, etc. * ********************************************************/int weekdays(numb)double numb;{double dd;int day;dd = numb;while (dd > 28000.0) dd = dd - 28000.0;while (dd < 0) dd = dd + 28000.0;day = dd;day = ((day + 1) % 7) + 1;return(day);}/********************************************************* FRACT - This routine takes a double float number ** and returns the fractional part as a double ** float number * ********************************************************/double fract(numb)double numb;{int inumb;double fnumb;while (numb < -32767) numb += 32767;while (numb > 32767) numb -= 32767;inumb = numb;fnumb = inumb;return(numb-fnumb);} /* end FRACT *//********************************************************* FLOOR - This routine takes a double float number ** and returns the next smallest integer *********************************************************/double floor(numb)double numb;{double fract(), intg();double out;out = intg(numb);if (numb < 0 && fract(numb) != 0) out -= 1.0;return(out);} /* end FLOOR *//********************************************************* INTG - This routine takes a double float number ** and returns the integer part as a double ** float number * ********************************************************/double intg(numb)double numb;{double fract();return(numb - fract(numb));} /* end INTG */。
(完整版)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语言-万年历
#include"stdio.h"void main(){int i,j,yeardays;int n=0,monthdays=0;int d=0,week,sum_days;int a[12]={31,28,31,30,31,30,31,31,30,31,30,31};int b[5][7];for(i=0;i<=5;i++)for(j=0;j<=6;j++)b[i][j]=' ';int y,m;char ch=' ';scanf("%d,%d",&y,&m);for(i=1980;i<=(y-1);i++)if(i%4==0&&i%100!=0||i%400==0)n+=1;yeardays=365*(y-1980-n)+n*366;if(y%4==0&&y%100!=0||y%400==0)a[1]=29;for(i=1;i<=m-1;i++)monthdays+=a[i];sum_days=yeardays+monthdays;printf(" Sun Mon Tue Wen Tur Fri Sar ");printf("\n");week=sum_days%7;/* switch(week){case 0:printf("%10c",ch);for(i=1;i<=a[m-1];i++){printf("%5d",i);if((i+2)%7==0)printf("\n");}break;case 1:printf("%15c",ch);for(i=1;i<=a[m-1];i++){printf("%5d",i);if((i+3)%7==0)printf("\n");}break;case 2:printf("%20c",ch);for(i=1;i<=a[m-1];i++){printf("%5d",i);if((i+4)%7==0)printf("\n");}break;case 3:printf("%25",ch);for(i=1;i<=a[m-1];i++){printf("%5d",i);if((i+5)%7==0)printf("\n");}break;case 4:printf("%30c",ch);for(i=1;i<=a[m-1];i++){printf("%5d",i);if((i+6)%7==0)printf("\n");}break;case 5:for(i=1;i<=a[m-1];i++){printf("%5d",i);if(i%7==0)printf("\n");}break;case 6:printf("%5c",ch);for(i=1;i<=a[m-1];i++){printf("%5d",i);if((i+1)%7==0)printf("\n");default:printf("error\n");}}*/if(week=5)week=-2;if(week=6)week=-1;week=week+2;for(i=0;i<=5;i++){for(j=week;j<=6;j++){if(d>a[m-1])beark;b[i][j]=++d;}week=0;}for(i=0;i<=5;i++)for(j=0;j<=6;j++)printf("%5d",b[i][j]);printf("\n");}。
万年历C语言代码
//ÍòÄêÀú#include <stdio.h>//±íÍ·void print_head(int x,int y){printf("\n\n************************************************************ ********************\n\n");printf ("\t\t\t\t%d %d\n\n",x,y);printf ("\t\t\t SUN MON TUE WED THU FRI SAT\n");printf ("\t\t\t");}//ÈÕÀúµÄÖмävoid print_month(int x,int y){int i;char space[7]={' '};for (i=1;i<=x;i++){printf ("%4c",space[i]);}for (i=1;i<=y;i++){if ((i+x)%7==1){printf ("\n\t\t\t%4d",i);}else{printf ("%4d",i);}}printf("\n\n************************************************************ ********************\n\n");}//¼ÆËãÖ¸¶¨ÄêÔµÄÌìÊýint days_of_month(int x,int y){int z;switch (y){case 1:case 3:case 5:case 7:case 8:case 10:case 12: z=31;break;case 4:case 6:case 9:case 11: z=30;break;case 2:{if ((x%4==0&&x%100!=0)||(x%400==0)){z=29;}else{z=28;}break;}}return z;} //¼ÆËãÖ¸¶¨ÄêÔÂ1ºÅÊÇÐÇÆÚ¼¸int leap(int x,int y){int z,i,moday;z=(x+(x-1)/4-(x-1)/100+(x-1)/400)%7;for (i=1;i<y;i++){moday=days_of_month(x,i); //ǯÌ×µ÷Óú¯Êýz=(z+moday)%7;}return z;}void main(){do{int days,year,month,firstday;char choose;do{printf ("\n\nÇëÊäÈëÐèÒª²éѯµÄÄê·Ý(0000~9999):\n\n");scanf ("%d",&year);if (year<0||year>9999){printf ("WANNING:ERROR,ÇëÖØÐÂÊäÈë!");}}while (year<0||year>9999);printf ("\n\n");do{printf ("ÇëÊäÈëÐèÒª²éѯµÄÔ·Ý(0~12)\n\n\n");scanf ("%d",&month);if (month<=0||month>12){printf ("WANNING:ERROR,ÇëÖØÐÂÊäÈë!");}} while (month<=0||month>12);printf ("\n\n");days=days_of_month(year,month); //µ÷Óú¯Êýfirstday=leap(year,month);print_head(year,month);print_month(firstday,days);choose=getchar();printf ("\n\n\n");printf("ÇëÎÊÊÇ·ñ¼ÌÐø£¿(y/n):\n\n");scanf("%c",&choose);if (choose=='n'||choose=='N'){break;}}while(1<2);}。
万年历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语言程序源代码
数字万年历简易C语言程序源代码#include"reg52.h"#define uchar unsigned char#define uint unsigned intsbit rs=P2^0; // lcd 控制端sbit en=P2^2; // lcd 控制端sbit all=P2^1; // lcd 控制端sbit s0=P1^5; //时间调节sbit s1=P1^6;sbit s2=P1^7;sbit voice=P2^7;int nt;sbit DQ=P2^6;sbit DS1302_CLK = P2^3; //实时时钟时钟线引脚sbit DS1302_IO = P2^4; //实时时钟数据线引脚sbit DS1302_RST = P2^5; //实时时钟复位线引脚sbit ACC0 = ACC^0;sbit ACC7 = ACC^7;unsigned char time;#define ads_y 0#define ads_mo 3#define ads_d 6#define ads_w 9#define ads_h 65#define ads_m 68#define ads_s 71#define DS1302_SECOND 0x80 //写入ds地址宏定义#define DS1302_MINUTE 0x82#define DS1302_HOUR 0x84#define DS1302_WEEK 0x8A#define DS1302_DAY0x86#define DS1302_MONTH 0x88#define DS1302_YEAR 0x8Cvoid delay1(unsigned int i) //ds 延时函数放在前边是为了让EP 两次存储之间延时可以调用{while(i--);}void init_ds() //ds 初始化函数{unsigned char x=0;DQ=1; //DQ复位delay1(8); //稍做延时DQ=0; //单片机将DQ拉低delay1(80); //精确延时大于480usDQ=1; //拉高总线delay1(10);x=DQ; //稍做延时后如果x=0则初始化成功x=1则初始化失败delay1(5);}unsigned char read_ds() ///ds 读一个字节{unsigned char i=0;unsigned char dat=0;for(i=8;i>0;i--){DQ=0; // 给脉冲信号dat>>=1;DQ=1; // 给脉冲信号if(DQ)dat|=0x80;delay1(5);}return(dat);}void write_ds(unsigned char dat) ///写一个字节{unsigned char i=0;for(i=8;i>0;i--){DQ=0;DQ=dat&0x01;delay1(5);DQ=1;dat>>=1;}delay1(5);}void get_nt() //获取温度{unsigned char a=0;unsigned char b=0;init_ds();write_ds(0xCC); // 跳过读序号列号的操作write_ds(0x44); // 启动温度转换delay1(10);init_ds();write_ds(0xCC); //跳过读序号列号的操作write_ds(0xBE); //读取温度寄存器等(共可读9个寄存器)前两个就是温度a=read_ds();b=read_ds();nt=0;nt=nt+b;nt=nt<<8;nt=nt+a;nt=nt*0.625; //此ds18b20 最低位为0.5 扩大十倍}void delay_1302(uint n) //按键长延时{while(n--);}void delay(uchar n) //lcd 延时子程序{uchar i,j;for(i=0;i<n;i++)< bdsfid="161" p=""></n;i++)<>for(j=0;j<10;j++);}void write_com(char com) //lcd comond in LCD控制字写入函数{en=0;P3=com;rs=0;delay(1);en=1;delay(2);en=0;delay(2);}void write_byte(char byte) //lcd data in LCD数据写入函数{en=0;P3=byte;rs=1;delay(1);en=1;delay(2);en=0;delay(2);}void init_lcd_com() //lcd init LCD初始化{all=0;write_com(0x38);write_com(0x0c);write_com(0x06);}void DS1302InputByte(unsigned char d) //实时时钟写入一字节(内部函数){unsigned char i;ACC = d;for(i=8; i>0; i--){DS1302_IO = ACC0; //相当于汇编中的RRCDS1302_CLK = 1;DS1302_CLK = 0;ACC = ACC >> 1;}}unsigned char DS1302OutputByte(void) //实时时钟读取一字节(内部函数){unsigned char i;for(i=8; i>0; i--){ACC = ACC >>1; //相当于汇编中的RRCACC7 = DS1302_IO;DS1302_CLK = 1;DS1302_CLK = 0;}return(ACC);}void Write1302(unsigned char ucAddr, unsigned char ucDa) //ucAddr: DS1302地址, ucData: 要写的数据DS1302_RST = 0;DS1302_CLK = 0;DS1302_RST = 1;DS1302InputByte(ucAddr); // 地址,命令DS1302InputByte(ucDa); // 写1Byte数据DS1302_CLK = 1;DS1302_RST = 0;}unsigned char Read1302(unsigned char ucAddr) //读取DS1302某地址的数据{unsigned char ucData;DS1302_RST = 0;DS1302_CLK = 0;DS1302_RST = 1;DS1302InputByte(ucAddr|0x01); // 地址,命令ucData = DS1302OutputByte(); // 读1Byte数据DS1302_CLK = 1;DS1302_RST = 0;return(ucData);}void DS1302_SetProtect(bit flag) //是否写保护{if(flag)Write1302(0x8E,0x10);elseWrite1302(0x8E,0x00);}void DS1302_SetTime(unsigned char Address, unsigned char V alue) // 关键函数向内写入时间{DS1302_SetProtect(0);Write1302(Address, ((V alue/10)<<4 | (V alue%10)));}void DS1302_GetTime(unsigned char xy) //关键函数向外读出时间{unsigned char ReadV alue;ReadV alue = Read1302(xy);time=((ReadV alue&0x70)>>4)*10+(ReadV alue&0x0F);}void display_nt(char ads,uchar t) //将读出时间显示char ge,shi;write_com(0x80+ads);shi=t%100/10;ge=t%10;write_byte(shi+'0');write_byte(ge+'0');}void display_nt2(char ads,uchar t) //将读出星期显示{ write_com(0x80+ads);write_byte(t+'0');}void get_dis() //获得时间并显示{DS1302_GetTime(DS1302_YEAR);display_nt(ads_y,time);DS1302_GetTime(DS1302_MONTH);display_nt(ads_mo,time);DS1302_GetTime(DS1302_DAY);display_nt(ads_d,time);DS1302_GetTime(DS1302_WEEK);display_nt2(ads_w,time);DS1302_GetTime(DS1302_HOUR);display_nt(ads_h,time);DS1302_GetTime(DS1302_MINUTE);display_nt(ads_m,time);DS1302_GetTime(DS1302_SECOND);display_nt(ads_s,time);}void set_time() //三按键设置时间{if(s0==0){write_com(0x0f); //开闪烁write_com(0x80+ads_m+1);while(s0==0);delay_1302(30000);while(s0==1){if(s1==0){DS1302_GetTime(DS1302_MINUTE); time++;DS1302_SetTime(DS1302_MINUTE,time); display_nt(ads_m,time);write_com(0x80+ads_m+1);delay_1302(30000);}if(s2==0){DS1302_GetTime(DS1302_MINUTE); time--;DS1302_SetTime(DS1302_MINUTE,time); display_nt(ads_m,time);write_com(0x80+ads_m+1);delay_1302(30000);}}write_com(0x80+ads_h+1);while(s0==0);delay_1302(30000);while(s0==1){if(s1==0){DS1302_GetTime(DS1302_HOUR); time++;DS1302_SetTime(DS1302_HOUR,time); display_nt(ads_h,time);write_com(0x80+ads_h+1);delay_1302(30000);}if(s2==0){DS1302_GetTime(DS1302_HOUR); time--;DS1302_SetTime(DS1302_HOUR,time); display_nt(ads_h,time);write_com(0x80+ads_h+1);delay_1302(30000);}}write_com(0x80+ads_w);while(s0==0);delay_1302(30000);while(s0==1){if(s1==0){DS1302_GetTime(DS1302_WEEK); time++;DS1302_SetTime(DS1302_WEEK,time); display_nt2(ads_w,time);write_com(0x80+ads_w);delay_1302(30000);}if(s2==0){DS1302_GetTime(DS1302_WEEK); time--;DS1302_SetTime(DS1302_WEEK,time); display_nt2(ads_w,time);write_com(0x80+ads_w);delay_1302(30000);}}write_com(0x80+ads_d+1);while(s0==0);delay_1302(30000);while(s0==1){if(s1==0){DS1302_GetTime(DS1302_DAY);time++;DS1302_SetTime(DS1302_DAY,time); display_nt(ads_d,time);write_com(0x80+ads_d+1);delay_1302(30000);}if(s2==0){DS1302_GetTime(DS1302_DAY);time--;DS1302_SetTime(DS1302_DAY,time);display_nt(ads_d,time);write_com(0x80+ads_d+1);delay_1302(30000);}}write_com(0x80+ads_mo+1);while(s0==0);delay_1302(30000);while(s0==1){if(s1==0){DS1302_GetTime(DS1302_MONTH); time++;DS1302_SetTime(DS1302_MONTH,time); display_nt(ads_mo,time);write_com(0x80+ads_mo+1);delay_1302(30000);}if(s2==0){DS1302_GetTime(DS1302_MONTH); time--;DS1302_SetTime(DS1302_MONTH,time); display_nt(ads_mo,time);write_com(0x80+ads_mo+1);delay_1302(30000);}}write_com(0x80+ads_y+1);while(s0==0);delay_1302(30000);while(s0==1){if(s1==0){DS1302_GetTime(DS1302_YEAR); time++;DS1302_SetTime(DS1302_YEAR,time); display_nt(ads_y,time);write_com(0x80+ads_y+1);delay_1302(30000);}if(s2==0){DS1302_GetTime(DS1302_YEAR); time--;DS1302_SetTime(DS1302_YEAR,time); display_nt(ads_y,time);write_com(0x80+ads_y+1);delay_1302(30000);}}write_com(0x0c);while(s0==0);delay_1302(30000);}}void init_lcd_dis() //显示初始化{write_com(0x80+2);write_byte('*');write_com(0x80+5);write_byte('*');write_com(0x80+8);write_byte('-');write_com(0x80+67);write_byte(':');write_com(0x80+70);write_byte(':');}void my() //右下角显示函数{char *pp;char i;code char p[]=" hou fei see a girl and say I LOVE YOU replay I LOVE YOU too ";pp=p;if(time<=60){write_com(0x80+74);for(i=0;i<=5;i++){write_byte(*(pp+time));pp++;}}}void display_nntt(int t) //当前温度显示{char ge,shi,bai;if(t<0){write_com(0x80+11);write_byte('-');t=-t;}else{write_com(0x80+11);write_byte('+');}bai=t/100;shi=t%100/10;ge=t%10;write_byte(bai+'0');write_byte(shi+'0');write_byte('.');write_byte(ge+'0');}void main(){init_lcd_com();init_lcd_dis();DS1302_SetTime(DS1302_SECOND,00); while(1){get_dis();set_time();get_nt();display_nntt(nt); my();}}。
用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语言课程设计简易万年历
/**湖北师范学院信息工程1203班朱文峰**简易万年历* 1、输入年份,判断是否为闰年*2、输入年月日,判断改日为星期几*3、输入年份,打出12个月历,输入月份,打出该月的日历* 4、要求用多个函数实现*/#include<stdio.h>#include<stdlib.h>#include<windows.h>//每月的天数,闰年二月要加1int days[12]={31,28,31,30,31,30,31,31,30,31,30,31};//判断是否位闰年int isLeapYear(int year){if(year%4 == 0 && year%100 != 0 || year%400 == 0)return 1;elsereturn 0;}//判断某天为星期几int whichWeekday(int year, int month, int day){int weekday;//公式中要把1月和2月换成是上一年的13月和14月if (month == 1 || month == 2){month += 12;year -= 1;}//公式weekday=(day+2*month+3*(month+1)/5+year+year/4-year/100+year/400)%7;return weekday+1;}//打印某年某月的月历void yearMonth(int year, int month){int i,j=0;int weekday;//计算这个月第一天是星期几weekday = whichWeekday(year, month, 1);printf("\n%d年%d月\n",year,month);printf("------------------------------------------------\n");printf("星期一星期二星期三星期四星期五星期六星期天\n");if(isLeapYear(year) && month == 2)days[1] = days[1] + 1;printf("");for(i = 1; i < weekday; i ++)printf(" ");for(i = 0; i < 8 - weekday; i ++){printf("%6d", i+1);printf(" ");}printf("\n");for(i = 9-weekday; i <= days[month-1]; i ++,j++){if(j == 7){j = 0;printf("\n");}printf("%6d ", i);}printf("\n------------------------------------------------\n");}//输入年份,打出12个月历,输入月份,打出该月的日历void monthDay(int year){int i;char c;int month;for(i = 0; i < 12; i ++)yearMonth(year,i+1);printf("\n\n");printf("是否查看日历(y/n):");getchar();scanf("%c",&c);if(c == 'y'){printf("请输入月份:");scanf("%d", &month);yearMonth(year,month);}elseexit(0);}//主菜单void menu(){printf("-----------------------------------------------\n");printf(" ");printf("c语言课程设计-万年历\n\n");printf("***********************************************\n\n");printf("1、输入年份,判断是否为闰年\n");printf("2、输入年月日,判断该日为星期几\n");printf("3、输入年份,打出12个月历,输入月份,打出该月的日历\n\n");printf("***********************************************\n\n");}//判断是否继续void isContinue(){char c;printf("是否继续(y/n):");getchar();scanf("%c", &c);if(c == 'y')return;else{printf("");exit(0);}}//主函数void main(){int num;int year;int month;int day;int weekday;while(1){system("CLS");//清屏menu();printf("请输入对应操作:");scanf("%d", &num);switch(num){case 1:{printf("请输入年份:");scanf("%d", &year);if(isLeapYear(year))printf("%d年是闰年\n",year);elseprintf("%d年不是闰年\n");isContinue();break;}case 2:{printf("请输入年月日,以空格隔开:");scanf("%d%d%d", &year,&month,&day);weekday = whichWeekday(year, month, day);printf("这天是星期%d\n",weekday);isContinue();break;}case 3:{printf("请输入年份:");scanf("%d", &year);monthDay(year);isContinue();break;}default:{printf("您的输入有误");Sleep(1000);//延时一秒钟break;}}}}。
万年历 c语言程序代码
char *p[12]={"long","she","ma","yang","hou","ji","gou","zhu","shu","niu","hu","tu"};
int i,j,k,m,n,f1,f2,year,d;
}
getch();
}
void xg()
{int year,month,day,n;
int sum=0,sum1=0,sum2=0,l=0,i,j,k,y,y1,m1,d1,
a[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int i,j,k,m,flag,year,month,d;
clrscr();
printf("qing shu ru nian fen he yue fen\n");
scanf("%d%d",&year,&month);
printf("\nthe calendar of %d\n",year);
printf("\n");
if(flag)
break;
}
}
printf(" ");
for(k=0;k<27;k++)
printf("=");
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
}
if(TotalOfDate%7==0&&i!=day)
cout<<endl;
}
cout<<endl<<endl;
}
int main()
{
Date date;
int NumberOfFeb,a[12];
for(year_temp=1;year_temp<year;year_temp++)
{
if(year_temp%400==0||(year_temp%100!=0&&year_temp%4==0)) NumberOfThisYear=366;
else NumberOfThisYear=365;
TotalOfDate+=NumberOfThisYear;
}
return TotalOfDate;
}
void PrintDate(int day)
{
cout<<"--------------------------------------------------"<<endl;
cout<<" 日 一 二 三 四 五 六"<<endl;
int week;
week=TotalOfDate%7;
for(int j=1;j<=7*week+5;j++)
cout<<" ";
for (i=1;i<=day;i++)
cout<<"请输入待查询的年份:"<<endl;
date.Inputyear();
if(date.Getyear()%400==0||date.Getyear()%100!=0&&date.Getyear()%4==0) NumberOfFeb=29;
else NumberOfFeb=28;
int GetTotalOfDate();
};
void Date::Inputyear()
{
cin>>year;
}
int Date::Getyear()
{
return year;
}
int Date::GetTotalOfDate()
{
int year_temp,TotalOfDate=1,NumberOfThisYear;
*/
#include<iostream>
using namespace std;
int TotalOfDate;
void PrintDate(int);
class Date
{
private:
int year;
public:
void Inputyear();
int Getyear();
TotalOfDate=date.GetTotalOfDate();
a[0]=a[2]=a[4]=a[6]=a[7]=a[9]=a[11]=31;
a[1]=NumberOfFeb;
a[3]=a[5]=a[8]=a[10]=30;
cout<<" 公元"<<date.Getyear()<<"年"<<endl;
/*简易万年历(C++控制台应用程序)
* Copyright (C) 2013 by ZhangXu, Nanjing University of Posts and Telecommunications.
* ALL RIGHTS RESERVED.
* E-mail: zx9999998@
{
if(i!=1&&TotalOfDate%7==0) cout<<" ";
if(i<10)
{
cout<<i<<" ";
TotalOfDate++;
}
else
{
cout<<i<<" ";
cout<<endl;
for(int i=1;i<=12;i++)
{
cout<<" "<<i<<"月"<<endl;
PrintDate(a[i-1]);
}
return 0;
}