万年历C++源代码
C 万年历及公历农历转换源代码1
scanf("%d.%d.%d",&gyear,&gmonth,&gday); if(gyear%4==0 && gyear%100!=0 || gyear%400==0) months[2]=29; else months[2]=28; /*以下是计算在该公历年的第几天*/
whatday=gPastday[gmonth]+gday; if((gyear%4==0 && gyear%100!=0 || gyear%400==0) && (gmonth>2)) whatday++; /*上如果是闰年和月份大于二则在该公历年的第几天数+1*/ /*计算该年春节在公历年的第几天*/
clrscr();
}
}
getch();
}
/*公历每月前面的天数*/ const int gPastday[13]={0,0,31,59,90,120,151,181,212,243,273,304,334};
months[13]={0,31,0,31,30,31,30,31,31,30,31,30,31};
{case 1:printf("
* 1 * "); break;
case 3:printf("
* 3 * "); break;
case 5:printf("
* 5 * "); break;
case 7:printf("
* 7 * "); break;
case 9:printf("
* 9 * ");break;
{
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语言万年历代码
屌神NO.1#include <stdio.h>#include <stdlib.h>#include <stdlib.h>#include <conio.h> /清屏函数的头文件*/#define X " Sun Mon Tue Wed Thu Fri Sat"void menu();int getday(int year,int month,int date);int isleap(int year);void print(int n);int day(int year);void printcalendar(int year);void menu(){system("cls"); /*清除屏幕上所有文字*/printf("\nTHIS IS THE MENU OF THE PROGRAM !");printf("\nYOU CAN CHOOSE THE NUMBER FOR THE FUNCTIOM:");printf("\n\n");printf("1 Find the day by year-month-date.\n");printf("2 Find out whether the year you input is a leap year.\n");printf("3 Print the calendar of the year you input.\n");printf("4 Exit.\n\n");printf("Input your choice:");}/*函数定义,将在主函数中调用*/int getday(int year,int month,int date){int isleap(int year);int flag,s,i;int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};int cont=0;flag=isleap(year);if(flag==1){a[2]++; /*修改二月份天数*/}for(i=1;i<month;i++){cont=cont+a[i];}cont=cont+date;s=year+1+(year-1)/4+(year-1)/100+(year-1)/400+cont;return s%7;}/*利用公式求星期几*/int isleap(int year){if(year%4==0&&year%100||year%400==0){return 1;}else{return 0;}}/*判定闰年*/void print(int n){int i;for(i=0;i<n;i++) printf(" ");}/*打印空格,排版使用*/int day(int year){long a,b;if(year<=2000){a=2000-year;b=6-(a+a/4-a/100+a/400)%7;return b;}else{a=year-2000;b=(a+1+(a-1)/4-(a-1)/100+(a-1)/400)%7+6;return b%7;}}/*打印日历函数*/void printcalendar(int year){int i,j,k,m,n,f1,f2,d;int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};printf("\nThe calendar of the year %d.\n\n",year);d=day(year);if(isleap(year)==1){a[2]++;}for(i=1;i<=12;i+=2){m=0; n=0; f1=0; f2=0;switch(i){case 1:printf(" Januray 1 ");break;case 3:printf(" March 3 ");break;case 5:printf(" May 5 ");break;case 7:printf(" July 7 "); break;case 9:printf(" September 9 ");break;case 11:printf(" Nevember 11 ");break;}print(21); /*打印空格,隔开奇偶月份名*/switch(i+1){case 2:printf(" February 2 "); break;case 4:printf(" April 4 "); break;case 6:printf(" June 6 "); break;case 8:printf(" August 8 "); break;case 10:printf(" October 10 "); break;case 12:printf(" December 12"); break;}printf("\n");printf(X); /*宏调用,打印星期字符串*/print(6); /*打印空格,隔开奇偶月份数据*/printf(X);printf("\n");for(j=0;j<6;j++){if(j==0){print(d*4); /*每个日期数采用个空格的宽度,即4字节。
C语言的万年历
int month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; int day1=0,m1=0;
if(m>1&&m<=12) {
for(m1=1;m1<m;m1++) day1+=month[m1];
day1=day1+d; } else if(m=1)
} d1=y*Y+count; eek(int d) { switch(d%7) { case 0: printf("Sunday\n");break; case 1: printf("Monday\n");break; case 2: printf("Tuesday\n");break; case 3: printf("Wednesday\n");break; case 4: printf("Thursday\n");break; case 5: printf("Friaday\n");break; case 6: printf("Saturday\n");break; }
最近准备毕业设计,难啊。一时无聊,用 C 写了一个万年历,放到这来,让喜爱编程的朋友交流下, 希望大家多指点! 此万年历只供大家交流,请勿为了应付作业直接 COPY!
这个万年历的主要思想就是找到输入年份的距离公元 0 年 1 月 1 日的天数,我将这一天定义为了 被认为是一周的开始——星期天,如果你不喜欢这么定义,可以自己更改!不过貌似现在的电子日 历都是讲公元 0 年 1 月 1 日定为星期天的,为了和世界接轨,还是别改了!哈哈!
c语言 万年历
c wannianli ---------------------------------------------------------*/ c = 0x00; y = 0x01; m = 0x01; d = 0x01; cx = BcdToBin(c);//百年 yx = BcdToBin(y);//年 mx = BcdToBin(m);//月 dx = BcdToBin(d);//日 WDay = WeekDay(cx, yx, mx, dx);//取星期和月天数 Week = WDay >> 5;//得到星期 Day = WDay & 0x1f;//得到最大月天数 /*--------------------------------------------------------1918年1月21日 星期一 ---------------------------------------------------------*/ c = 0x19; y = 0x18; m = 0x01; d = 0x21; cx = BcdToBin(c);//百年 yx = BcdToBin(y);//年 mx = BcdToBin(m);//月 dx = BcdToBin(d);//日 WDay = WeekDay(cx, yx, mx, dx);//取星期和月天数 Week = WDay >> 5;//得到星期 Day = WDay & 0x1f;//得到最大月天数 /*--------------------------------------------------------9999年12月31日 星期天 ---------------------------------------------------------*/ c = 0x00; y = 0x01; m = 0x01; d = 0x01; cx = BcdToBin(c);//百年 yx = BcdToBin(y);//年 mx = BcdToBin(m);//月 dx = BcdToBin(d);//日 WDay = WeekDay(cx, yx, mx, dx);//取星期和月天数 Week = WDay >> 5;//得到星期 Day = WDay & 0x1f;//得到最大月天数 /*--------------------------------------------------------2004年6月18日 星期五 ---------------------------------------------------------*/ c = 0x20; y = 0x04; m = 0x06; d = 0x18; cx = BcdToBin(c);//百年 yx = BcdToBin(y);//年 mx = BcdToBin(m);//月 dx = BcdToBin(d);//日 WDay = WeekDay20(yx, mx, dx);//取星期和月天数 Week = WDay >> 5;//得到星期 Day = WDay & 0x1f;//得到最大月天数 /*--------------------------------------------------------2018年3月8日 星期四 ---------------------------------------------------------*/ c = 0x20; y = 0x18; m = 0x03; d = 0x08; cx = BcdToBin(c);//百年 yx = BcdToBin(y);//年 mx = BcdToBin(m);//月 dx = BcdToBin(d);//日 WDay = WeekDay20(yx, mx, dx);//取星期和月天数 Week = WDay >> 5;//得到星期 Day = WDay & 0x1f;//得到最大月天数 while(1); }
万年历c语言源程序
#include <stdio.h>#include <windows.h>#include <wincon.h>#include<string.h>#include<stdlib.h>#include<conio.h>#include<time.h>#include<math.h>#define NULL 0CONSOLE_SCREEN_BUFFER_INFO csbiInfo; extern WINBASEAPI HWND WINAPI GetConsoleWindow(); time_t T;struct tm * now;int min,sec;int hour,nowyear,nowmonth,nowday;void ti2(){time ( &T );now = localtime ( &T );hour=now->tm_hour%12;min=now->tm_min-15;sec=now->tm_sec-15;}void ti(){time ( &T );now = localtime ( &T );hour=now->tm_hour;min=now->tm_min;sec=now->tm_sec;nowyear=now->tm_year+1900;nowmonth=now->tm_mon+1;nowday=now->tm_mday;}int yearbak=0;void clock_sz();int pd( int year);void huizs(int line_head_month);void hzdy(int year,int nowmonth_hz);void menu();void clear();int main(int argc, char* argv[]){int x=0;ti();clock_sz();hzdy(nowyear,nowmonth);menu();return 0;}void clear(){int i;HWND hwnd;HANDLE hOut;HDC hdc;HBRUSH hbr;COORD pos={1,4};hwnd=GetConsoleWindow();hdc = GetDC(hwnd);hOut = GetStdHandle(STD_OUTPUT_HANDLE);hbr= CreateSolidBrush(RGB(0,0,0));SelectObject(hdc,hbr);Rectangle(hdc,0,65,670,470);SetConsoleCursorPosition(hOut, pos);for(i=0;i<10;i++)printf(" \n ");SetConsoleCursorPosition(hOut, pos);Rectangle(hdc,0,65,670,470);ReleaseDC(hwnd, hdc);}void menu(){int year=0,xyear=0,x, xy=0,i ;struct re{int top;int left;int right;int bottom;}rt[13];HWND hwnd;HDC hdc,dc;HBRUSH hbr;COORD pos3_1 = {1, 4},pos3_2= {1, 1},pos = {1, 4},pos2_3 = {1, 6},pos2_4 = {1, 7};INPUT_RECORD mouseRec;DWORD state = 0, res=0;POINT pt;HPEN pn;HANDLE hOut, hIn;hwnd=GetConsoleWindow();//得到控制台窗口句柄hdc = GetDC(hwnd); //得到画图设备句柄dc = GetDC(hwnd);//画刷hbr= CreateSolidBrush(RGB(255,0,0));SelectObject(dc,hbr);for(rt[1].left=20,i=2;i<=12;i++) rt[i].left=rt[i-1].left+50;for(rt[1].right=50,i=2;i<=12;i++) rt[i].right=rt[i-1].right+50; //定位按钮for(i=0;i<=12;i++) rt[i].top=40;for(i=0;i<=12;i++) rt[i].bottom=60;hOut = GetStdHandle(STD_OUTPUT_HANDLE);hIn=GetStdHandle(STD_INPUT_HANDLE);pn=CreatePen(PS_SOLID,1,RGB(255,0,255));GetClientRect(hwnd, &rt);SelectObject(hdc, pn);SetBkMode(hdc,TRANSPARENT);MoveToEx(hdc,1,35,NULL);LineTo(hdc,620,35);LineTo(hdc,620,62);LineTo(hdc,1,62);LineTo(hdc,1,35);pn=CreatePen(PS_SOLID,2,RGB(255,255,0));SelectObject(hdc, pn);MoveToEx(hdc,5,75,NULL);LineTo(hdc,45,75);hbr= CreateSolidBrush(RGB(0,0,190));SelectObject(dc,hbr);for(i=1;i<=12;i++)Rectangle(dc,rt[i].left,rt[i].top,rt[i].right,rt[i].bottom);SetTextColor(hdc,RGB(0,255,255));TextOut(hdc,280,10,TEXT("万年历"),6);//输出文本SetTextColor(hdc,RGB(255,255,0));////设颜色TextOut(hdc,rt[1].left,rt[1].top,TEXT(" 1"),3);//输出文本TextOut(hdc,rt[1].left+=50,rt[1].top,TEXT(" 2"),3);//输出文本TextOut(hdc,rt[1].left+=50,rt[1].top,TEXT(" 3"),3);//输出文本TextOut(hdc,rt[1].left+=50,rt[1].top,TEXT(" 4"),3);//输出文本TextOut(hdc,rt[1].left+=50,rt[1].top,TEXT(" 5"),3);//输出文本TextOut(hdc,rt[1].left+=50,rt[1].top,TEXT(" 6"),3);//输出文本TextOut(hdc,rt[1].left+=50,rt[1].top,TEXT(" 7"),3);//输出文本TextOut(hdc,rt[1].left+=50,rt[1].top,TEXT(" 8"),3);//输出文本TextOut(hdc,rt[1].left+=50,rt[1].top,TEXT(" 9"),3);//输出文本TextOut(hdc,rt[1].left+=50,rt[1].top,TEXT(" 0"),3);//输出文本TextOut(hdc,rt[1].left+=50,rt[1].top,TEXT("确定"),4);//输出文本TextOut(hdc,rt[1].left+=50,rt[1].top,TEXT("清除"),4);//输出文本TextOut(hdc,40,350,TEXT("提示:双击窗口退出"),18);//输出文本SetConsoleCursorPosition(hOut, pos3_1);ShowWindow(hwnd,SW_SHOW);SetConsoleTextAttribute(hOut, 10);for(;;){SetConsoleTextAttribute(hOut, 10);ReadConsoleInput(hIn, &mouseRec, 1, &res);Sleep(100);if (mouseRec.EventType == MOUSE_EVENT){if (mouseRec.Event.MouseEvent.dwEventFlags == DOUBLE_CLICK) break;if (mouseRec.Event.MouseEvent.dwButtonState == FROM_LEFT_1ST_BUTTON_PRESSED){GetCursorPos(&pt);ScreenToClient(hwnd,&pt);if(pt.x>20&& pt.x<50 &&pt.y>rt[1].top && pt.y<rt[1].bottom){if(xyear<4) printf("1");xyear++;if(xyear==1) year=1*1000;if(xyear==2) year=year+1*100;if(xyear==3) year=year+1*10;if(xyear==4){year=year+1;printf("\n你选择的年为%d",year);}continue;}else if(pt.x>rt[2].left && pt.x<rt[2].right &&pt.y>rt[2].top && pt.y<rt[2].bottom){if(xyear<4) printf("2");xyear++;if(xyear==1) year=2*1000;if(xyear==2) year=year+2*100;if(xyear==3) year=year+2*10;if(xyear==4){year=year+2;printf("\n你选择的年为%d",year);}continue;}else if(pt.x>rt[3].left && pt.x<rt[3].right &&pt.y>rt[3].top && pt.y<rt[3].bottom){if(xyear<4) printf("3");xyear++;if(xyear==1) year=3*1000;if(xyear==2) year=year+3*100;if(xyear==3) year=year+3*10;if(xyear==4){year=year+3;printf("\n你选择的年为%d",year);}continue;}else if(pt.x>rt[4].left && pt.x<rt[4].right &&pt.y>rt[4].top && pt.y<rt[4].bottom){if(xyear<4) printf("4");xyear++;if(xyear==1) year=4*1000;if(xyear==2) year=year+4*100;if(xyear==3) year=year+4*10;if(xyear==4){year=year+4;printf("\n你选择的年为%d",year);}continue;}else if(pt.x>rt[5].left && pt.x<rt[5].right &&pt.y>rt[5].top && pt.y<rt[5].bottom){if(xyear<4) printf("5");xyear++;if(xyear==1) year=5*1000;if(xyear==2) year=year+5*100;if(xyear==3) year=year+5*10;if(xyear==4){year=year+5;printf("\n你选择的年为%d",year);}continue;}else if(pt.x>rt[6].left && pt.x<rt[6].right &&pt.y>rt[6].top && pt.y<rt[6].bottom){if(xyear<4)printf("6");xyear++;if(xyear==1) year=6*1000;if(xyear==2) year=year+6*100;if(xyear==3) year=year+6*10;if(xyear==4){year=year+6;printf("\n你选择的年为%d",year);}continue;}else if(pt.x>rt[7].left && pt.x<rt[7].right &&pt.y>rt[7].top && pt.y<rt[7].bottom){if(xyear<4)printf("7");xyear++;if(xyear==1) year=7*1000;if(xyear==2) year=year+7*100;if(xyear==3) year=year+7*10;if(xyear==4){year=year+7;printf("\n你选择的年为%d",year);}continue;}else if(pt.x>rt[8].left && pt.x<rt[8].right &&pt.y>rt[8].top && pt.y<rt[8].bottom){if(xyear<4)printf("8");xyear++;if(xyear==1) year=8*1000;if(xyear==2) year=year+8*100;if(xyear==3) year=year+8*10;if(xyear==4){year=year+8;printf("\n你选择的年为%d",year);}continue;}else if(pt.x>rt[9].left && pt.x<rt[9].right &&pt.y>rt[9].top && pt.y<rt[9].bottom){if(xyear<4)printf("9");xyear++;if(xyear==1) year=9*1000;if(xyear==2) year=year+9*100;if(xyear==3) year=year+9*10;if(xyear==4){year=year+9;printf("\n你选择的年为%d",year);}continue;}else if(pt.x>rt[10].left && pt.x<rt[10].right &&pt.y>rt[10].top && pt.y<rt[10].bottom){if(xyear<4) printf("0");xyear++;if(xyear==1) year=0*1000;if(xyear==2) year=year+0*100;if(xyear==3) year=year+0*10;if(xyear==4){year=year+0;printf("\n你选择的年为%d",year);}continue;}else if(pt.x>rt[11].left && pt.x<rt[11].right &&pt.y>rt[11].top && pt.y<rt[10].bottom){if(xyear>=1&&year!=0){clear();yearbak=year;SetConsoleCursorPosition(hOut, pos3_2);printf("公元%d年",yearbak);SetConsoleCursorPosition(hOut, pos3_1);for(i=1;i<=6;i+=3)huizs(i);x=MessageBox(NULL,"是否显示后六个月?", "提示",MB_YESNO);if(x==6) {SetConsoleTextAttribute(hOut, 14);clear();for(i=7;i<=12;i+=3)huizs(i);}}else printf("输入不合法,请点击清除重新输入");continue;}else if(pt.x>rt[12].left && pt.x<rt[12].right &&pt.y>rt[12].top && pt.y<rt[12].bottom){xyear=0;year=0;clear();clock_sz();hzdy(nowyear,nowmonth);pn=CreatePen(PS_SOLID,2,RGB(255,255,0));SelectObject(hdc, pn);//选画笔MoveToEx(hdc,5,75,NULL);LineTo(hdc,45,75);SetConsoleCursorPosition(hOut, pos);continue;}};}}ReleaseDC(hwnd,hdc);}int pd( int year){int pr=0;if((year%100==0)&&(year%400==0))pr=1;else if(year%4==0&&year%100!=0)pr=1;else pr=0;return pr;}void huizs(int line_head_month){int i=0,j=0,k=0,month=0,n=0,daysum=0,jlw=0;int monthhead[13]={0},mlt[3]={1,1,1};int endline=0,test=0;int year=0;year=yearbak;for(i=1;i<year;i++){if(pd(i))daysum+=366;else daysum+=365;}j=daysum%7;monthhead[0]=j;for(month=1;month<=12;month++){if(pd(year)&&month==2) n=29;else if(pd(year)==0&&month==2) n=28;else if(month==4||month==6||month==9||month==11) n=30;else n=31;monthhead[month]=(monthhead[month-1]+n)%7;}while(test<=5){for(month=line_head_month;month<=(line_head_month+2);month++){if(month%3==1&&endline==0){printf("\t%d月\t\t\t%d月%d月\n",month,month+1,month+2);printf("一二三四五六日一二三四五六日一二三四五六日\n");}if(endline==0){for(k=0;k<monthhead[month-1];k++)printf(" ");j=monthhead[month-1];}if(endline==0) i=1;else i=mlt[month-1];for(;j<7;i++,j++){if(pd(year)&&month==2) n=29;else if(pd(year)==0&&month==2) n=28;else if(month==4||month==6||month==9||month==11) n=30;else n=31;if(i>n){for(k=0;k<7-j;k++)printf(" ");break;}printf("%-3.0d",i);}printf(" ");mlt[month-1]=i;if(month%3==0){printf("\n");endline=1;}j=0;}test++;}}void hzdy(int year,int nowmonth_hz){int i=0,j=0,k=0,month=0,n=0,daysum=0,jlw=0;int monthhead[13]={0},mlt[3]={1,1,1};int endline=0,test=0;for(i=1;i<year;i++){if(pd(i))daysum+=366;else daysum+=365;}j=daysum%7;monthhead[0]=j;for(month=1;month<=12;month++){if(pd(year)&&month==2) n=29;else if(pd(year)==0&&month==2) n=28;//平年else if(month==4||month==6||month==9||month==11) n=30;else n=31;monthhead[month]=(monthhead[month-1]+n)%7;}if(pd(year)&&nowmonth_hz==2) n=29;//闰年else if(pd(year)==0&&nowmonth_hz==2) n=28;//平年else if(nowmonth_hz==4||nowmonth_hz==6||nowmonth_hz==9||nowmonth_hz==11) n=30;//4,6,9,11月else n=31;printf("\n\n\n\n\n\n\n\n 当前时间:%d年%d月%d日%d时%d分\n\n",nowyear,nowmonth,nowday,hour,min);printf("\t一二三四五六日\n\t");for(k=0;k<monthhead[nowmonth_hz-1];k++)printf(" ");j=monthhead[nowmonth_hz-1];for(i=1;i<=n;i++,j++){if(j==7){printf("\n\t");j=0;}printf("%-3.0d",i);}printf("\n");}void clock_sz(){float a,b,c;float x=0,y=0,ex=100,ey=160,radian=0,oldx,oldy,radius=90;float mx=0,my=0,oldmx,oldmy,mradius=40;float hx=0,hy=0,oldhx,oldhy,hradius=20;intkd_r1,kd_r2,kd_radius=170,kd_radius1,old_kd_x,old_kd_y,kd_radian=0,k=0,q=0,oldk,oldq;HWND hwnd;HANDLE hOut;HDC hdc;COLORREF C1=RGB(0,0,0),C2=RGB(0,0,0);HBRUSH hbr,hbr1,hbr2;HPEN hpn,gpn,rpn,ppn2,ypn,bpn,kdpn,rkdpn,dotpn,blue,black,blkdpn,pkdpn,hpn2;hwnd=GetConsoleWindow();hdc = GetDC(hwnd);hOut = GetStdHandle(STD_OUTPUT_HANDLE);hbr= CreateSolidBrush(RGB(0,100,0));hbr1= CreateSolidBrush(C1);hbr2= CreateSolidBrush(RGB(0,0,150));hpn2=CreatePen(PS_SOLID,1,RGB(255,0,0));rpn=CreatePen(PS_SOLID,1,RGB(255,0,0));ppn2=CreatePen(PS_SOLID,3,RGB(255,255,0)); hpn=CreatePen(PS_SOLID,1,RGB(0,255,255)); blue=CreatePen(PS_SOLID,3,RGB(0,0,255)); bpn=CreatePen(PS_SOLID,1,RGB(255,255,255)); gpn=CreatePen(PS_SOLID,2,RGB(0,255,0)); pkdpn=CreatePen(PS_SOLID,3,RGB(0,255,255)); kdpn=CreatePen(PS_SOLID,1,RGB(255,255,0)); rkdpn=CreatePen(PS_SOLID,4,RGB(255,0,0)); blkdpn=CreatePen(PS_SOLID,6,RGB(0,0,0)); black=CreatePen(PS_SOLID,4,C1);ex=400;//时钟圆心位置ey=230;while(kd_radian<=360){if(kd_radian%5==0){if(kd_radian%90==0){kd_radius=130;SelectObject(hdc,rkdpn);}else{kd_radius=125;SelectObject(hdc,pkdpn);}}else{kd_radius=130;SelectObject(hdc, kdpn);kd_radius1=120;}y=kd_radius*sin(kd_radian/180.0*3.14);x=kd_radius*cos(kd_radian/180.0*3.14);MoveToEx(hdc,ex,ey,NULL);LineTo(hdc,ex+x,ey+y);y=kd_radius1*sin(kd_radian/180.0*3.14);x=kd_radius1*cos(kd_radian/180.0*3.14);old_kd_x=x;old_kd_y=y;SelectObject(hdc,blkdpn);MoveToEx(hdc,ex,ey,NULL);LineTo(hdc,ex+old_kd_x,ey+old_kd_y);kd_radian+=6;};SetTextColor(hdc,RGB(0,255,0));SetBkColor(hdc,RGB(0,0,0));TextOut(hdc,ex+kd_radius+8,ey-7,TEXT("3"),1);TextOut(hdc,ex-4,ey+kd_radius+3,TEXT("6"),1);TextOut(hdc,ex-kd_radius-15,ey-5,TEXT("9"),1);TextOut(hdc,ex-7,ey-kd_radius-18,TEXT("12"),2);radius=110;mradius=90;//分针半径hradius=70;//时针半径x=0,y=0;radian=0;SetTextColor(hdc,RGB(0,255,225));////设颜色SetBkColor(hdc,RGB(0,0,0));////设颜色ti2();a=sec*6/180.0*3.14;b=min*6/180.0*3.14;c=(hour*30.0-90.0+(min+15)/2.0)/180.0*3.14;SetTextColor(hdc,RGB(0,255,255));my=mradius*sin(b);mx=mradius*cos(b);SelectObject(hdc, gpn);MoveToEx(hdc,ex,ey,NULL);LineTo(hdc,ex+mx,ey+my);LineTo(hdc,ex+mx,ey+my);hy=hradius*sin(c);hx=hradius*cos(c);SelectObject(hdc, blue);MoveToEx(hdc,ex,ey,NULL);LineTo(hdc,ex+hx,ey+hy);ReleaseDC(hwnd, hdc);}。
(完整版)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语言基础代码编写的简单的万年历程序
#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>//±íÍ·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语言实训--万年历源代码
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);
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("输入年份:");
scanf("%d",&year);
printf("the calendar of the year%d\n",year);
printf("\n");
printf("=============================\n");
for(i=1;i<13;i++)
case 10:day+=273+flag;break;
case 11:day+=304+flag;break;
case 12:day+=334+flag;break;
printf("星期%d",number);
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语言程序源代码
数字万年历简易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语言代码
万年历C语言代码#include <stdio.h>main(){for(;;){int year,month,a,b,c,m,n=28;/*定义变量*/long e;printf("请输入年份");scanf("%d",&year);e=year;e--; /*前一年*/e=(e*365+e/4)%7; /*计算这一年的第一天是星期几*/m=e; /*把第一天的日期赋给m*/if((year%4==0)||(year%100!=0)&&(year%400!=0))/*如果是闰年*/n++;printf("%d的日历:",year);for(month=1;month<=12;month++){if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)/*这几个月每个月都是31天*/{c=0;printf("\n");printf(" %d月\n",month);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) /*如果是小于10,空一格,大于10,前后空*/printf(" ");printf(" %d ",a);m++;if(m==7)/*一行排满,开始换行。
(指的是这个月的最后一行)*/m=0;}printf("\n");}else{if(month==4||month==6||month==9||month==11||month==2) {if(month==2)/*判断2月份*/{c=0;printf("\n");printf(" %d月\n",month);printf(" ");printf(" 日一二三四五六\n");for(b=1;b<=m;b++){c++;printf(" ");}for(a=1;a<=n;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",month);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<reg52.h>#include<intrins.h>#include<absacc.h>#include<math.h>#define uchar unsigned char#define uint unsigned int#define rst573 XBYTE[0X1000]#define y4 XBYTE[0X8000]#define y5 XBYTE[0Xa000]#define y6 XBYTE[0Xc000]#define y7 XBYTE[0Xe000]sbit scl1302=P1^7;sbit IO=P2^3;sbit rst1302=P1^3;sbit lcden=P1^2;sbit lcdwr=P2^1;sbit lcdrs=P2^0;sbit s5=P3^2;sbit s4=P3^3;sbit s6=P3^1;sbit s7=P3^0;uint t;sbit DQ=P1^4;float tt;uchar *riqi="20 - - "; uchar *xingqi="week "; uchar *shijian=" - - "; uchar *wedu="28.7C";uchar time[8],num;int nian,yue,ri,xq=1,shi,fen,miao; char count;void delay(uint z){uint x,y;for(x=z;x>0;x--)for(y=120;y>0;y--); }void delayus(uint t){for(;t>0;t--);}void init(){rst573;y4;rst573;P0=0x00;y6;rst573;P0=0xa0;y7;rst573;}/**************************1602***********************/void write_com(uchar com){lcdrs=0;lcdwr=0;P0=com;delay(5);lcden=1;delay(5);lcden=0;}void initlcd(){lcdwr=0;write_com(0x38);write_com(0x0c);write_com(0x06);write_com(0x01);}void write_data(uchar date){lcdrs=1;lcdwr=0;P0=date;delay(5);lcden=1;delay(5);lcden=0;}/***********************************************1302**************/ void writebyte(uchar add,date){uchar i;IO=0;rst1302=1;for(i=0;i<8;i++){scl1302=0;IO=add&0x01;scl1302=1;add>>=1;}for(i=0;i<8;i++){scl1302=0;IO=date&0x01;scl1302=1;date>>=1;}rst1302=0;}uchar readbyte(uchar add){uchar i,temp;scl1302=0;IO=0;rst1302=1;for(i=0;i<8;i++){scl1302=0;IO=add&0x01;scl1302=1;add>>=1;}for(i=0;i<8;i++){scl1302=1;temp>>=1;scl1302=0;if(IO)temp|=0x80;}return temp;}void set_1302(){writebyte(0x8e,0x00);writebyte(0x8c,nian);writebyte(0x8a,xq);writebyte(0x88,yue);writebyte(0x86,ri);writebyte(0x84,shi);writebyte(0x82,fen);writebyte(0x80,0x00);writebyte(0x8e,0x80);}void read_1302(uchar *p){p[0]=readbyte(0x81);writebyte(0x00,0x00);p[1]=readbyte(0x83);writebyte(0x00,0x00);p[2]=readbyte(0x85);writebyte(0x00,0x00);p[3]=readbyte(0x87);writebyte(0x00,0x00);p[4]=readbyte(0x89);writebyte(0x00,0x00);p[5]=readbyte(0x8b);writebyte(0x00,0x00);p[6]=readbyte(0x8d);writebyte(0x00,0x00);fen=p[1];shi=p[2];ri=p[3];yue=p[4];xq=p[5];nian=p[6];}/*************************************18b20******************/ void init_ds18b20() //18B20初始化{char presence=1;WR=0;while(presence){while(presence){DQ=1;_nop_();_nop_();DQ=0;delayus(50);DQ=1;delayus(6);presence=DQ;delayus(45); //延时500 uspresence=~DQ;}DQ=1; //拉高电平}/****************************************************************************** **/void writeonechar(unsigned char dat) //写一个字节{uchar i=0;for(i=8;i>0;i--){DQ=1;_nop_();_nop_();DQ=0;DQ=dat&0x01;delayus(6);DQ=1;dat>>=1;}DQ=1;}/****************************************************************************** ***/uchar readonechar(void) //读一个字节{uchar i=0;uchar dat=0;for(i=8;i>0;i--){DQ=1;_nop_();_nop_();dat>>=1;DQ=0;_nop_();_nop_();_nop_();_nop_();DQ=1;_nop_();_nop_();_nop_();_nop_();if(DQ)dat|=0x80;delayus(6);}return(dat);}/****************************************************************************** */uchar display_zh() //把子节转化为十进制{init_ds18b20();writeonechar(0xcc);writeonechar(0x44);init_ds18b20();_nop_();_nop_(); _nop_();_nop_();writeonechar(0xcc);writeonechar(0xbe);a=readonechar();b=readonechar();t=b;t<<=8;t=t|a;tt=t*0.0625;t=tt*10+0.5;return t;}void display1(){uchar i;write_com(0x80); //2011-11-11 23-14-59 week 1 28.7℃for(i=0;i<2;i++){write_data(riqi[i]);}write_com(0x84); //2011-11-11 23-14-59 week 1 28.7℃write_data(riqi[4]);write_com(0x87); //2011-11-11 23-14-59 week 1 28.7℃write_data(riqi[7]);write_com(0x8d);write_data('.');write_com(0x8f);write_data('C');write_com(0xc2);write_data(shijian[2]);write_com(0xc5);write_data(shijian[5]);write_com(0xc9);for(i=0;i<4;i++){write_data(xingqi[i]);}writebyte(0x80,0x00);write_com(0x82);write_data(nian/16+'0');write_data(nian%16+'0');write_com(0x85);write_data(yue/16+'0');write_data(yue%16+'0');write_com(0x88);write_data(ri/16+'0');write_data(ri%16+'0');display_zh();write_com(0x8b);write_data(t%1000/100+'0');write_data(t%100/10+'0');write_com(0x8e);write_data(t%10+'0');/********************************/write_com(0xc0);write_data(shi/16+'0');write_data(shi%16+'0');write_com(0xc3);write_data(fen/16+'0');write_data(fen%16+'0');write_com(0xc6);write_data(time[0]/16+'0');write_data(time[0]%16+'0');write_com(0xce);write_data(xq+'0');}void jian(){if(s4==0){writebyte(0x8e,0x00); writebyte(0x80,0x00);num=0;set_1302();}if(s7==0){while(!s7);num++;}switch(num){case 1:writebyte(0x8e,0x00);if(s6==0){while(!s6);fen++; writebyte(0x80,0x80);}if(fen==10)//10fen=16;if(fen==26)//20fen=32;if(fen==42)//30fen=48;if(fen==58)//40fen=64;if(fen==74)//50fen=80;if(fen==90)//60fen=0;if(s5==0){while(!s5);fen--;writebyte(0x80,0x80);}if(fen==-1)//10fen=89;if(fen==79)//20fen=73;if(fen==63)//30fen=57;if(fen==47)//40fen=41;if(fen==31)//50fen=25;if(fen==15)//50fen=9;writebyte(0x82,fen);write_com(0xc3);display1();break;case 2:writebyte(0x8e,0x00);if(s6==0){while(!s6); shi++;writebyte(0x80,0x80);} if(shi==10)//10shi=16;if(shi==26)//20shi=32;if(shi==36)//30shi=0;if(s5==0){while(!s5);shi--;writebyte(0x80,0x80);}if(shi==-1)//30shi=35;if(shi==31)//40shi=25;if(shi==15)//50shi=9;write_com(0xc0);writebyte(0x84,shi);display1();break;case 3:writebyte(0x8e,0x00);if(s6==0){while(!s6);ri++;writebyte(0x80,0x80);}if(ri==10)//10ri=16;if(ri==26)//20ri=32;if(ri==42)//30ri=48;if(ri==50)//60ri=0;if(s5==0){while(!s5);ri--;writebyte(0x80,0x80);}if(ri==-1)//10ri=49;if(ri==47)//40ri=41;if(ri==31)//50ri=25;if(ri==15)//50ri=9;write_com(0x88);writebyte(0x86,ri);display1();;break;case 4:writebyte(0x8e,0x00);if(s6==0){while(!s6);yue++;writebyte(0x80,0x80);}if(yue==10)//10yue=16;if(yue==19)//20yue=0;if(s5==0){while(!s5);yue--;writebyte(0x80,0x80);}if(yue==-1)//10yue=18;if(yue==16)//10yue=10;write_com(0x85);writebyte(0x88,yue);display1();;break;case 5:writebyte(0x8e,0x00);if(s6==0){while(!s6);nian++;writebyte(0x80,0x80);}if(nian==10)//10nian=16;if(nian==26)//20nian=32;if(nian==42)//30nian=48;if(nian==58)//40nian=64;if(nian==74)//50nian=80;if(nian==90)//60nian=96;if(nian==106)//70nian=112;if(nian==122)//80nian=128;if(nian==138)//90nian=144;if(nian==154)//60nian=0;if(s5==0){while(!s5);nian--;writebyte(0x80,0x80);}if(nian==-1)//10nian=153;if(nian==143)//90nian=137;if(nian==127)//80nian=121;if(nian==111)//70nian=105;if(nian==95)//60nian=89;if(nian==79)//50nian=73;if(nian==63)//40nian=57;if(nian==47)//30nian=41;if(nian==31)//20nian=25;if(nian==-15)//10nian=9;write_com(0x82);writebyte(0x8c,nian);display1();break;case 6:writebyte(0x8e,0x00);if(s6==0){while(!s6);xq++;writebyte(0x80,0x80);}if(xq==8)xq=1;if(xq==0)xq=7;if(s5==0){while(!s5); xq--;writebyte(0x80,0x80);}if(xq==-1)xq=7;write_com(0xce);writebyte(0x8a,xq);display1();break;case 7: writebyte(0x8e,0x00);writebyte(0x80,0x00);num=0;set_1302();break;}}void main(){init();initlcd();set_1302();while(1){ display1();jian();read_1302(time);}}。
万年历 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("=");
c语言——万年历程序
#include<stdio.h>#include<stdlib.h>char*month_str[]={"January","February","March","April","May","June","July","August ","September","October","November","December"};char*week[]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Sat urday"};int IsLeapYear(int year) /*find out the year is leap year or not*/{if((year%4==0&&year%100!=0)||(year%400==0)) //这里是判断是否是闰年的return 1; //如果是闰年就返回值1elsereturn 0;//不是的话返回0}int month_day(int year,int month) //这个函数用来判断这年的月分有多少天的{int mon_day[]={31,28,31,30,31,30,31,31,30,31,30,31};if(IsLeapYear(year)&&month==2) /*判断是判断是否是闰年,如果是闰年而且这个月是2月那这个月有29天*/return 29;elsereturn(mon_day[month-1]);}int DaySearch(int year,int month,int day) /*这个函数是计算输入的日期对应的星期*/{int c=0;float s;int m;for(m=1;m<month;m++)c=c+month_day(year,m); //这是计算输入的月分的累计天数c=c+day; //计算日期在这一年中是第几天s=year-1+(int)(year-1)/4+(int )(year-1)/100+(int)(year-1)/400-40+c; /*这是计算日期对应的星期公式,这个公式可在网上查到*/return ((int)s%7); //与上语句同属计算日期对应的星期}int PrintAllYear(int year)/*这个函数是用来输出全年的日历*/{int temp;int i,j;printf("\n\n%d Calander\n",year);for(i=1;i<=12;i++){printf("\n\n%s(%d)\n",month_str[i-1],i); //输出月分名称printf("0 1 2 3 4 5 6 \n");printf("S M T W T F S \n\n");temp=DaySearch(year,i,1);for(j=1;j<=month_day(year,i)+temp;j++){if(j-temp<=0)printf(" ");else if(j-temp<10)printf("%d ",j-temp);elseprintf("%d ",j-temp);if(j%7==0)printf("\n");}}return 0;}int main(){int option,da;char ch;int year,month,day;printf("Copyright @ 2005 TianQian All rights reserved!:):):)");printf("\n\nWelcome to use the WanNianLi system!\n");while(1){printf("\nPlease select the service you need:\n"); //用来提示选择执行功能printf("\n1 Search what day the day is"); //选择1时,用来计算这一天是星期几printf("\n2 Search whether the year is leap year or not"); //计算是否这年是闰年printf("\n3 Print the calander of the whole year"); //输入全年的日历printf("\n4 Exit\n"); //选择退出程序scanf("%d",&option);switch(option) //用来选择执行{case 1:while(1){printf("\nPlease input the year,month and day(XXXX,XX,XX):"); //提示输入scanf("%d,%d,%d,%c",&year,&month,&day); //读入数据da=DaySearch(year,month,day); //调用DaySearch()函数来计算是星期几printf("\n%d-%d-%d is %s,do you want tocontinue?(Y/N)",year,month,day,week[da]);fflush(stdin); //刷新输入缓冲区scanf("%c",&ch);if(ch=='N'||ch=='n')break;}break;case 2: /*当为2时,进行相应运算*/while(1){printf("\nPlease input the year which needs searched?(XXXX)");scanf("%d",&year);if(IsLeapYear(year))printf("\n%d is Leap year,do you want to continue?(Y/N)",year);elseprintf("\n%d is not Leap year,do you want to continue(Y/N)?",year); fflush(stdin);scanf("%c",&ch);if(ch=='N'||ch=='n')break;}break;case 3: /*当为3时运行相应的运算*/while(1){printf("\nPlease input the year which needs printed(XXXX)");scanf("%d",&year);PrintAllYear(year);printf("\nDo you want to continue to print(Y/N)?");fflush(stdin);scanf("%c",&ch);if(ch=='N'||ch=='n')break;}break;case 4:fflush(stdin);printf("Are you sure?(Y/N)");scanf("%c",&ch);if(ch=='Y'||ch=='y')exit(1);break;default:printf("\nError:Sorry,there is no this service now!\n"); break;}}return 0;}。
C万年历源代码
#inclu de <i ostre am>#inclu de <i omani p>us ing n amesp ace s td;class Date{pr ivate:in t yea r;i nt mo nth;intday;intmonth Day[12];publi c:Date(int y=1, i nt m=1, in t d=1):yea r(y),month(m),d ay(d) {mont hDay[0]=31;m onthD ay[1]=28;mon thDay[2]=31;month Day[3]=30;mo nthDa y[4]=31;mont hDay[5]=30;m onthD ay[6]=31;mon thDay[7]=31;month Day[8]=30;mo nthDa y[9]=31;mont hDay[10]=30;month Day[11]=31;}vo id Se tYear(inty) {year=y; }voi d Set Month(intm) {month=m; }vo id Se tDay(int d) { d ay=d; }int G etYea r() c onst{ ret urn y ear;}i nt Ge tMont h() c onst{ ret urn m onth; }int G etDay() co nst { retu rn da y; }int GetM onthD ay(co nst i nt i){if(i==2&&Islea pyear(year))retu rn 29;r eturn mont hDay[i-1];}boo l Isl eapye ar(in t y)//判断是否为闰年。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
#include "iostream"
using namespace std;
//#include "stdafx.h"//1900.1.1是星期1
int yeardaysform1900(int year);
int mouthdays(int year,int mouth);
void printyear();
void printmouth(int ,int);
void findday();
char *dayss[]={"日","一","二","三","四","五","六"};
int main()
{
cout<<"******************************************************************* *********"<<endl;
cout<<"******************************* 欢迎本万年历!
******************************"<<endl;
cout<<"******************************************************************* *********"<<endl;
do{
cout<<"李金香,请选择:"<<endl;
cout<<"--------------------------1.显示莫一年的万年历
------------------------------"<<endl;
cout<<"--------------------------2.显示莫一月的万年历
------------------------------"<<endl;
cout<<"--------------------------3.查询莫一天的
-------------------------------------"<<endl;
cout<<"--------------------------0.退出
---------------------------------------------"<<endl;
int choice;
cin>>choice;
hh:switch(choice)
{
case 1:printyear();break;
case 2:
{ int year,mouth;cout<<"请输入年和月,如:2012 10"<<endl;
cin>>year>>mouth;
printmouth(year,mouth);break;}
case 3:findday();break;
case 0:exit(0);break;
default:cout<<"输入错误,请重新输入:"<<endl;
cin>>choice;goto hh;
}
}while(1);
return 0;
}
int yeardaysform1900(int year)
{
int i,days=0;
for(i=1990;i<year;i++)
{
if(i%4==0&&i%100!=0||i%400==0)
days+=366;
else
days+=365;
}
return days;}
int mouthdays(int year,int mouth)
{
int days;
bool aa;
if(year%4==0&&year%100!=0||year%400==0)aa=true;
else
aa=false;
switch(mouth)
{case 1:case 3:case 5:case 7:case 8:case 10:case 12: days=31;break;
case 2:if(aa)days=29;else days=28;break;
default:days=30;
}
return days;}
void printyear()
{
cout<<endl;
cout<<"请输入年:"<<endl;
cout<<endl<<endl;
int year;int i;
cin>>year;
for(i=1;i<13;i++)
{printmouth(year,i);for(int i=0;i<100000000;i++);}
}
void printmouth(int year,int mouth)
{
int i,days=0;
cout<<endl;
//int year,mouth;
//cout<<"请输入年和月,(如2012 3)"<<endl;
cout<<endl;
//cin>>year>>mouth;
days+=yeardaysform1900(year);
for(i=1;i<mouth;i++)
days+=mouthdays(year,i);
i=days%7;
int j=0;int aa=0;
cout<<year<<"年"<<mouth<<"月"<<endl;
for(j=0;j<7;j++)
cout<<dayss[j]<<" ";cout<<endl;
for(j=0;j<i+1;j++){
cout<<" ";aa++;
if(aa%7==0)cout<<endl;
}
for(j=1;j<=mouthdays(year,mouth);j++)
{
if(aa%7==0)cout<<endl;
cout<<j<<" ";aa++;
}cout<<endl;
}
void findday(){cout<<"请输入年月日,如:2012 10 1"<<endl; int year,mouth,day;
cin>>year>>mouth>>day;int totalday=0,i;
for(i=1900;i<year;i++)
totalday+=yeardaysform1900(i);
for(i=1;i<mouth;i++)
totalday+=mouthdays(year,i);
for(i=1;i<day;i++);
totalday+=i;
totalday%=7;
cout<<year<<"年"<<mouth<<"月"<<day<<"日"<<"是星期"<<dayss[totalday]<<endl; }。