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万年历源代码
#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)//判断是否为闰年。
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语言——万年历程序
#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语言实现源程序
万年历的C语言编程实现源程序:#include<stdio.h>#include<stdlib.h>int Isleapyear(int y)/*判断是否是闰年*/{if((y%4==0&&y%100!=0)||(y%400==0))return 1;elsereturn 0;}int Getdaysofmonth(int y,int m)/*确定某个月的天数*/{int months[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};if(Isleapyear(y))/*如果是闰年则2月份的天数改变为29*/ months[2]=29;return months[m];}int Gettotaldays(int y,int m)/*计算从1901年1月开始到给定年月的天数*/{intmonths[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};int days=0;int i,j;if((Isleapyear(y)))months[2]=29;for(i=1901;i<y;i++)/*从1901年1月开始计算,累加y年之前的天数*/{if(Isleapyear(i))days+=366;elsedays+=365;}for(j=1;j<m;j++)/*累加m月之后的天数*/days+=months[j];return days;}int Getfirstdayintable(int y,int m)/*计算给定年月的第一天在日历表中的位置*/{int d;d=Gettotaldays(y,m);d=d+3;/*1901年1月1日是星期二,在日历中星期二是第三个位置*/d=d%7;return d;}void Showdate(int y,int m)/*显示日历*/{int first;int d;int i,k;first=Getfirstdayintable(y,m);/*得到第一天在日历中的第一个位置*/d=Getdaysofmonth(y,m);/*得到这个月的天数*/k=0;printf("-------------------------------------\n");printf(" SUN MON TUE WEN THU FRI STA\n");for(i=1;i<first;i++)/*打印第一天之前的空格*/{printf(" ");k++;/*k用于确定日历中是否回车*/}for(i=1;i<=d;i++){printf("%5d",i);/*每个具体的日期占5个字符的宽度*/k++;if(k==7)/*每行打印7个日期数字后回车*/{printf("\n");k=0;}}printf("\n-------------------------------------\n"); }int main(){int y,m;printf("Input year:");scanf("%d",&y);printf("Input month:");scanf("%d",&m);Showdate(y,m);return 0;}欢迎您的下载,资料仅供参考!致力为企业和个人提供合同协议,策划案计划书,学习资料等等打造全网一站式需求。
c日历源代码
#include <stdio.h>#include <windows.h>void month(int a)//输出月份和星期{printf("\t");switch (a){case 1:printf("Janurary 1\t\t\t\t");case 2:printf("February 2");break;case 3:printf("March 3 \t\t\t\t");case 4:printf("April 4");break;case 5:printf("May 5 \t\t\t\t");case 6:printf("June 6");break;case 7:printf("July 7 \t\t\t\t");case 8:printf("August 8");break;case 9:printf("September 9 \t\t\t");case 10:printf("October 10");break;case 11:printf("November 11 \t\t\t");case 12:printf("December 12");break;}printf("\n\t");printf("Sun Mon Tue Wed Thu Fri Sat\t\t");printf("Sun Mon Tue Wed Thu Fri Sat\n\t");}int date(int a,int b,int c)//输出日期a为月份b为判断润平年r为某月最后一天的星期数{void space(int a);int i,j,n,m,x=1,y,k=0;switch (a){case 1:n=31;break;case 3:n=31;m=30;break;case 5:n=31;m=30;break;case 7:n=31;m=31;break;case 9:n=30;m=31;break;case 11:n=30;m=31;break;}if (a==1)if (b==0)m=28;elsem=29;for (i=1,j=c;i<=n;i++,j++){printf("%2d ",i);if (j==7 && i!=n){j=0;printf("\t\t");for (y=1;x<=m;y++){if (k==0){c=(c+n-1)%7+1;while (c>7)c=c-7;space(c);y=c;k=1;if (y<1)y=1;}printf("%2d ",x);if (y==7 && x!=m){x++;printf("\n\t");y=0;break;}if (x==m && y==7){x++;printf("\n\t");y=0;break;}if (x==m && y!=7)printf("\n\t");x++;}}if (i==n && j==7){j=0;i=0;break;}}if (i!=0)while (7-j){printf(" ");j=1+j;}printf("\t\t");if (x<=m)for (y=1;x<=m;y++,x++){printf("%2d ",x);if (y==7 && x!=m){printf("\n\t\t\t\t\t\t");y=0;}}printf("\n\t===========================\t\t");printf("===========================\n\n");if (y>7 || y==0)y=1;return y;}int leap(int a)//判断是否为闰年{int n;if ((a%4==0 && a%100!=0) || a%400==0)n=1;elsen=0;return n;}int print()//输出日历{void shxi(int a);void ganzhi(int a);void space(int a);int n,days,year,result,r,i,week,rem;while (1){printf("\t\t请输入年份:");SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),12|240);//设置字体颜色i=scanf("%d",&year);if (i==1){SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),0|240);break;}elsefflush(stdin);printf("\t\t错误输入!\n");SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),0|240);}ganzhi(year);shxi(year);n=leap(year);if (n)days=366;elsedays=365;result=(year-1+(year-1)/4-(year-1)/100+(year-1)/400+days)%7-n;//一月一号星期几的判断公式r=result+1;week=(days+result)/7;rem=(days +result)%7;if (rem!=0) week=week+rem/7+1;//计算这一年有多少周printf("\t\t\t\t\t%d周\n",week);printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");for (i=1;i<=12;i+=2){month(i);space(r);r=date(i,n,r);}printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");return 0;}void space(int a)//输出空格{int i;for (i=0;i<a-1;i++)printf(" ");}int main()//主程序输出选择菜单{void fprint();int n;system("color f0");//设置背景和字体颜色do{printf("\t\t* * * * * * * * * * * * * * * * * * * * * *\n");printf("\t\t*\t1---查询(Search) *\n");printf("\t\t*\t2---导出(Lead) *\n");printf("\t\t*\t0---关闭(Close) *\n");printf("\t\t* * * * * * * * * * * * * * * * * * * * * *\n");printf("\t\t请选择:");SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),12|240);//设置字体颜色scanf("%d",&n);system("cls");SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),0|240);switch (n){case 1:print();break;case 2:fprint();break;case 0:break;default:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),12|240);printf("\ t\t错误选择!请重选");}fflush(stdin);printf("\n");} while(n!=0);return 0;}void shxi(int a)//判断这一年的属性并输出{int s;if (a>=2008) //属性判断公式s=((a-2008)%100)%12+1;elses=13-((2008-a)%100)%12;switch (s){case 1:printf("鼠");break;case 2:printf("牛");break;case 3:printf("虎");break;case 4:printf("兔");break;case 5:printf("龙");break;case 6:printf("蛇");break;case 7:printf("马");break;case 8:printf("羊");break;case 9:printf("猴");break;case 10:printf("鸡");break;case 11:printf("狗");break;case 12:printf("猪");break;}}void ganzhi(int a)//判断天干地支{int g,z;g=(a-3)%10;//天干判断公式z=(a-3)%12;//地支判断公式printf("\t\t\t");switch (g){case 1:printf("甲");break;case 2:printf("乙");break;case 3:printf("丙");break;case 4:printf("丁");break;case 5:printf("戊");break;case 6:printf("己");break;case 7:printf("庚");break;case 8:printf("辛");break;case 9:printf("壬");break;case 0:printf("癸");break;}switch (z){case 1:printf("子");break;case 2:printf("丑");break;case 3:printf("寅");break;case 4:printf("卯");break;case 5:printf("辰");break;case 6:printf("巳");break;case 8:printf("未");break;case 9:printf("申");break;case 10:printf("酉");break;case 11:printf("戌");break;case 0:printf("亥");break;}printf("年\t");}FILE *fp;//定义文件指针void fmonth(int a)//导出月份和星期{fprintf(fp,"\t");switch (a){case 1:fprintf(fp,"Janurary 1\t\t\t\t");case 2:fprintf(fp,"February 2");break;case 3:fprintf(fp,"March 3 \t\t\t\t");case 4:fprintf(fp,"April 4");break;case 5:fprintf(fp,"May 5 \t\t\t\t");case 6:fprintf(fp,"June 6");break;case 7:fprintf(fp,"July 7 \t\t\t\t");case 8:fprintf(fp,"August 8");break;case 9:fprintf(fp,"September 9 \t\t\t");case 10:fprintf(fp,"October 10");break;case 11:fprintf(fp,"November 11 \t\t\t");case 12:fprintf(fp,"December 12");break;}fprintf(fp,"\n\t");fprintf(fp,"Sun Mon Tue Wed Thu Fri Sat\t\t");fprintf(fp,"Sun Mon Tue Wed Thu Fri Sat\n\t"); }int fdate(int a,int b,int c)//导出日期{int i,j,n,m,x=1,y,k=0,r;switch (a){case 1:n=31;break;case 3:n=31;m=30;break;case 5:n=31;m=30;break;case 7:n=31;m=31;break;case 11:n=30;m=31;break;}if (a==1)if (b==0)m=28;elsem=29;for (i=1,j=c;i<=n;i++,j++){fprintf(fp,"%2d ",i);if (j==7 && i!=n){j=0;fprintf(fp,"\t\t");for (y=1;x<=m;y++){if (k==0){c=(c+n-1)%7+1;while (c>7)c=c-7;for (r=0;r<c-1;r++)fprintf(fp," ");y=c;k=1;if (y<1)y=1;}fprintf(fp,"%2d ",x);if (y==7 && x!=m){x++;fprintf(fp,"\n\t");y=0;break;}if (x==m && y==7){x++;fprintf(fp,"\n\t");y=0;break;}if (x==m && y!=7)fprintf(fp,"\n\t");x++;}}if (i==n && j==7){j=0;i=0;break;}}if (i!=0)while (7-j){fprintf(fp," ");j=1+j;}fprintf(fp,"\t\t");if (x<=m)for (y=1;x<=m;y++,x++){fprintf(fp,"%2d ",x);if (y==7 && x!=m){fprintf(fp,"\n\t\t\t\t\t\t");y=0;}}fprintf(fp,"\n\t===========================\t\t");fprintf(fp,"===========================\n\n");if (y>7 || y==0)y=1;return y;}void fprint()//导出文件{void fshxi(int a);void fganzhi(int a);void fspace(int a);int n,days,year,result,r,i,week,rem;char filename[10],type[]=".txt";while (1){printf("\t\t请输入年份:");i=scanf("%d",&year);if (i==1)break;elsefflush(stdin);printf("\t\t错误输入!\n");}printf("\t\t请输入导出文件名:");scanf("%s",&filename);fp=fopen(strcat(filename,type),"w");//以写的方式打开文件fganzhi(year);fshxi(year);n=leap(year);if (n)days=366;elsedays=365;result=(year-1+(year-1)/4-(year-1)/100+(year-1)/400+days)%7-n;r=result+1;week=(days+result)/7;rem=(days +result)%7;if (rem!=0) week=week+rem/7+1;fprintf(fp,"\t\t\t\t\t\t\t\t%d周\n",week);fprintf(fp," * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");for (i=1;i<=12;i+=2){fmonth(i);fspace(r);r=fdate(i,n,r);}fprintf(fp," * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");fclose(fp);//关闭文件printf("\t\t已导出完成");}void fspace(int a)//导出空格{int i;for (i=0;i<a-1;i++)fprintf(fp," ");}void fshxi(int a)//导出属性{int s;if (a>=2008)s=((a-2008)%100)%12+1;elses=13-((2008-a)%100)%12;switch (s){case 1:fprintf(fp,"鼠");break;case 2:fprintf(fp,"牛");break;case 3:fprintf(fp,"虎");break;case 4:fprintf(fp,"兔");break;case 5:fprintf(fp,"龙");break;case 6:fprintf(fp,"蛇");break;case 7:fprintf(fp,"马");break;case 8:fprintf(fp,"羊");break;case 9:fprintf(fp,"猴");break;case 10:fprintf(fp,"鸡");break;case 11:fprintf(fp,"狗");break;case 12:fprintf(fp,"猪");break;}fprintf(fp,"\n");}void fganzhi(int a)//导出天干地支{int g,z;g=(a-3)%10;z=(a-3)%12;fprintf(fp,"\t\t\t%d年\t\t",a);switch (g){case 1:fprintf(fp,"甲");break;case 2:fprintf(fp,"乙");break;case 3:fprintf(fp,"丙");break;case 4:fprintf(fp,"丁");break;case 5:fprintf(fp,"戊");break;case 6:fprintf(fp,"己");break;case 7:fprintf(fp,"庚");break;case 8:fprintf(fp,"辛");break;case 9:fprintf(fp,"壬");break;case 0:fprintf(fp,"癸");break;}switch (z){case 1:fprintf(fp,"子");break;case 2:fprintf(fp,"丑");break;case 3:fprintf(fp,"寅");break;case 4:fprintf(fp,"卯");break;case 5:fprintf(fp,"辰");break;case 6:fprintf(fp,"巳");break;case 7:fprintf(fp,"午");break;case 8:fprintf(fp,"未");break;case 9:fprintf(fp,"申");break;case 10:fprintf(fp,"酉");break;case 11:fprintf(fp,"戌");break;case 0:fprintf(fp,"亥");break;}fprintf(fp,"年\t");}。
万年历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语言编写的万年历(源码)
#include <stdio.h>#include <stdlib.h>//记录平年和闰年各月的天数信息int days[2][13]={{0,31,28,31,30,31,30,31,31,30,31,30,31},{0,31,29,31,30,31,30,31,31,30,31,30,31}};//确定该年份是平年还是闰年int fun1(int year){if((year%4==0&&year%100!=0)||year%400==0)return 1;return 0;}//求出该年份以前有多少天int fun2(int year){int sum=0;if(year>1){for(int i=1;i<year;i++){int flag=fun1(i);for(int j=0;j<=12;j++){sum+=days[flag][j];}}}return sum;}//求出当前日期是该年份的第几天int fun3(int year,int month,int day){if(year>0){int sum=0;int flag=fun1(year);for(int i=0;i<month;i++)sum+=days[flag][i];sum+=day;return sum;}}//打印该年份的日历void fun4(int year){for(int month=1;month<=12;month++){int cnt=0;int onemonth[6][7];//用于盛放一个月的二维信息///////////////////////////////////////对一个月的二维信息必须进行初始化for(int x=0;x<6;x++)for(int y=0;y<7;y++)onemonth[x][y]=0;////////////////////////////////int flag=fun1(year);//判断记录该年份是闰年还是平年for(int day=1;day<=days[flag][month];day++){int sum=fun2(year)+fun3(year,month,day);//当前日期离公元第0日的天数?if(sum%7==0)//判断改天是星期几cnt++;//用于记录该月有几行信息?onemonth[cnt][sum%7]=day;//在相应位置填充值}////////////////////////////////////////打印头部信息printf("----------------------公元%d年%d月----------------------\n\n",year,month);printf("星期日星期一星期二星期三星期四星期五星期六\n\n");////////////////////////////////////////打印一个月的二维信息for(int i=0;i<=cnt;i++){for(int j=0;j<7;j++){if(onemonth[i][j]!=0)printf(" %d\t",onemonth[i][j]);elseprintf(" \t");}printf("\n");}printf("\n");}}void main(){system("cls");system("title=万年历"); system("color 0a");int year;int sum=0;printf("请输入年份:"); scanf("%d",&year);if(year>0)fun4(year);system("pause");main();}。
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语⾔实现⼀个简单⽇历满⾜三个需求:1.输⼊⼀个年份,输出是在屏幕上显⽰该年的⽇历。
假定输⼊的年份在1940-2040年之间。
2.输⼊年⽉,输出该⽉的⽇历。
3.输⼊年⽉⽇,输出距今天还有多少天,星期⼏,是否是公历节⽇。
最终完善版代码:复制代码代码如下:#include<stdio.h>#include <string.h>#include <time.h>#include <math.h>#include <windows.h>int year , month , day ;int day_of_month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};//char wek[7]={'周⽇','周⼀','周⼆','周三','周四','周五','周六'};int current_year,current_month,current_day;/************************************通⽤关键函数**************************************************/ void cls_screen(){printf("请按任意键返回!\n");getchar();getchar();system("cls");}void get_current_time() //获取当前时间{time_t timep;struct tm *p;time(&timep);p = gmtime(&timep);current_year=1900+p->tm_year;current_month=1+p->tm_mon;current_day=p->tm_mday;}int judgement (int y){if (y % 400 == 0 || (y % 100 !=0 && y %4 ==0))return 1 ;else return 0 ;}int show_week (int year , int month , int day){/*公式:w=(y+[y/4]+[c/4]-2c+[26(m+1)/10]+d-1)%7*/int w ,k; //记录周⼏int year_last=year %100,c=year/100 , m = month;if (month==1 ){year_last-=1 ;m=13 ;}else if (month==2){year_last-=1;m=14;}w = (year_last + year_last/4 + c/4 - 2*c +26*(m+1)/10+day-1); // abs 绝对值if (w<0){k=(w%7+7)%7;}else k=w%7;return k ;}/************************************第⼀部分**************************************************/void print_year (int year){int i , k ,x ,first_week;printf ("请输⼊想要查询的年⽉(格式如2012):");scanf ("%d",&year);printf("=======================%d年===========================\n",year);printf("\n");if (judgement(year)){day_of_month[1]=29;}else day_of_month[1]=28;for (i=1 ; i <13 ; i++){first_week = show_week(year,i,1);printf("=====================%d⽉⽇历如下========================\n",i); printf ("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");for (x=1;x<=first_week;x++){printf("\t");if (x%7==0) printf ("\n");}for (k=1;k<=day_of_month[i-1];k++){printf("%d\t",k);if (x%7==0) printf ("\n");x++;}printf("\n");printf("\n");printf("\n");}}/************************************第⼆部分**************************************************/void print_year_month (){int k ,x ,first_week;printf ("请输⼊想要查询的年⽉(格式如2012 12):");do{scanf ("%d %d",&year,&month);if (month<1||month>12){printf("您输⼊的⽉份有误哦~请输⼊正确的⽉份\n");printf ("请输⼊想要查询的年⽉(格式如2012 12):");}}while(1>month||month>12);printf("=====================%d年%d⽉======================\n",year,month); if (judgement(year)){day_of_month[1]=29;}else day_of_month[1]=28;first_week = show_week(year,month,1);printf ("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");for (x=1;x<=first_week;x++){printf("\t");if (x%7==0) printf ("\n");}for (k=1;k<=day_of_month[month-1];k++){printf("%d\t",k);if (x%7==0) printf ("\n");x++;}printf("\n");}/************************************第三部分**************************************************/int year_before_sumdays (int year,int month, int day){int days=0 ,i,judgement1;int temp_day=0 ,sum_days; ////printf ("%d,%d\n",current_year,current_month);judgement1=judgement(year);/*===================⽐当前少=====================*/if (year < current_year ){for (i = year+1;i < current_year ;i++){if (judgement(i)){days=days+356;}else days+=355;}for (i = month+1;i<=12;i++){days=days+day_of_month[i-1];}days = days + day_of_month[month-1]-day; //指定⽇⼦距离当年结束还有多少天 //printf("去年还有%d\n",days);for (i = 0;i < current_month-1;i++ ){if (judgement1){day_of_month[1]=29;}temp_day = temp_day + day_of_month[i];}//当前⽇⼦是这⼀年的多少天temp_day = temp_day + current_day;//printf("今天是第%d天\n",temp_day);sum_days=temp_day + days ;}/*===================⽐当前多=====================*/if (year > current_year ){for (i =current_year+1;i < current_year ;i++){if (judgement(i)){days=days+356;}else days+=355;}for (i = current_month+1;i<=12;i++){days=days+day_of_month[i-1];}days = days + day_of_month[month-1]-current_day; //指定⽇⼦距离当年结束还有多少天 //printf("去年还有%d\n",days);for (i = 0;i <month-1;i++ ){if (judgement1){day_of_month[1]=29;}temp_day = temp_day + day_of_month[i];}//当前⽇⼦是这⼀年的多少天temp_day = temp_day + day;//printf("今天是第%d天\n",temp_day);sum_days=temp_day + days ;}/*===================⽐当前⼀样=====================*/if (year == current_year ){if(month <current_month){for (i=month+1;i<current_month;i++){if (judgement1){day_of_month[1]=29;}days = days + day_of_month[i];}sum_days = days + current_day + day_of_month[month-1] - day ;}if (month>current_month){for (i=current_month+1;i<month;i++){if (judgement1){day_of_month[1]=29;}days = days + day_of_month[i];}sum_days = days + day + day_of_month[month-1] - current_day ;printf("%d\n",days);}if (month==current_month){sum_days= abs(day-current_day);}}return sum_days ;}void print(int year,int month,int day){int week;printf ("请输⼊想要查询的年⽉(格式如2012 12 12 ):");do{scanf ("%d %d %d",&year,&month,&day);if (judgement(year)){day_of_month[1]=29;}printf("\n");if (day<=0 || day >day_of_month[month-1])printf ("%d⽉没有%d,请重新输⼊(格式如2012 12 12 ):",month,day);}while(day<=0 || day >day_of_month[month-1]);week=show_week (year,month ,day);printf("\n");switch(month)//判断查找天是否阳历节⽇先由⽉份判断是否有节⽇的⽉份再由⽇判断是否为节⽇ {case 1:switch(day){case 1:printf("元旦") ;break;default:printf("不是阳历节⽇");}break;case 2:switch(day){case 14:printf("情⼈节(Valentines Day)");break;default:printf("不是阳历节⽇");}break;case 3:switch(day){case 8:printf("妇⼥节¨(Women's Day)");break;case 12:printf("植树节(Arbor Day)");break;default:printf("不是阳历节⽇");}break;case 4:switch(day){case 1:printf("愚⼈节(April Fools Day)");break;case 5:printf("清明节(Tomb-sweeping Day)");break;default:printf("不是阳历节⽇");}break;case 5:switch(day){case 1:printf("劳动节(Labor Day)");break;case 4:printf("中国青年节(Chinese Youth Day)");default:printf("不是阳历节⽇");}break;case 6:switch(day){case 1:printf("⼉童节(Children's Day)");break;default:printf("不是阳历节⽇");}break;case 8:switch(day){case 1:printf("建军节(the Army's Day)");break;default:printf("不是阳历节⽇");}break;case 9:switch(day){case 10:printf("教师节(Teacher's Day)");break;default:printf("不是阳历节⽇");}break;case 10:switch(day){case 1:printf("国庆节(National Day)");break;case 31:printf("万圣节(Helloween Day)");break;default:printf("不是阳历节⽇");}break;case 12:switch(day){case 25 :printf("圣诞节(Christmas Day)");break;default:printf("不是阳历节⽇");}break;}printf("\n");printf("%d年%d⽉%d号是:",year,month,day);switch(week)//判断所查找天是星期⼏{case 0:printf("Sunday");break;case 1:printf("Monday");break;case 2:printf("Tuesday");break;case 3:printf("Wednesday");;break;case 4:printf("Thursday");break;case 5:printf("Friday");break;case 6:printf("Saturday");break;}printf("\n");printf("距离今天有%d天\n",year_before_sumdays ( year, month, day));printf("\n");}/********************************************************************************************/void main (){int choice,year,month,day,flag=1;char c , k;for(;1;)//显⽰程序菜单,为永真,每次查找完回到程序菜单ì{printf("===================================菜单选项===================================\n"); printf("请选择:\n");printf("* * * * * * * * 1.查找某⼀年的年历 * * * * * * * *\n");printf("* * * * * * * * 2.查找某⼀⽉的⽉历 * * * * * * * *\n");printf("* * * * * * * * 3.查找某⼀天 * * * * * * * *\n");printf("* * * * * * * * 0.退出 * * * * * * * *\n");printf("==============================================================================\n"); printf("请输⼊您的选择: ");do{if (flag){c=getche();printf("\n");printf("确定选择%c吗? (y/Y )或者(n/N): ",c);}if (flag ){k=getche();// printf("\n");}if (k == 'y' || k == 'Y'){printf("\n");if (c=='\n'){printf("\n");printf("输⼊有误,请输⼊数字\n");printf("\n");printf("请输⼊您的选择: ");}else if (!isdigit(c)){printf("\n");printf("输⼊有误,请输⼊数字\n");printf("\n");printf("请输⼊您的选择: ");}else if (isdigit(c)){choice = c-'0' ;if (choice < 0 || choice > 3 ){printf("输⼊有误,请输⼊0-3之间的数字\n"); }else break ;}}else if (k=='n' || k=='N'){printf("\n");printf("你选择了否,请重新输⼊选项: ");flag=1;}if ((k != 'y'&& k!='Y'&& k!= 'n'&& k!='N')){printf("\n");printf("请输⼊y/n: ");flag=0;if (flag == 0){k=getche();printf("\n");//getchar();}}}while(1);if (choice==1){print_year(year);cls_screen();}else if (choice==2){print_year_month ();cls_screen();}else if (choice==3){get_current_time();print(year,month,day);cls_screen();}else if (choice==0)break;else{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<time.h>#include<stdlib.h>int judgeyear (int year){if(year%4==0&&year%100!=0||year%400==0)return 366;elsereturn 365;}int days_month (int month,int year){/*1,3,5,7,8,10,12每月31天*/if(month==1||month==3||month==5||month==7||month==8||month==10||month==12) return 31;/*4,6,9,11每月为30天*/if(month==4||month==6||month==9||month==11)return 30;/*2月判断是28还是29天*/if(month==2&&judgeyear(year)==366)return 29;elsereturn 28;}//计算用户输入的年份和今年相隔多少天int distance_inputyear_nowyear(int inputyear,int nowyear){int day_distance=0;if(inputyear<nowyear){for(int i=inputyear;i<nowyear;i++){if(judgeyear(i)==366)day_distance+=366;elseday_distance+=365;}}else if(inputyear>nowyear){for(int i=nowyear;i<inputyear;i++){if(judgeyear(i)==366)day_distance+=366;elseday_distance+=365;}}elseday_distance=0;// printf("%d年的第一天和今年第一天相隔%d天\n",inputyear,day_distance);return day_distance;}//获取今年第一天是星期几void firstday_weekday_nowyear(){int weekday_nowyear_firstday;//今年第一天星期几time_t tval;struct tm *now;tval = time(NULL);now = localtime(&tval);if(now->tm_yday%7<now->tm_wday)weekday_nowyear_firstday=(now->tm_wday-(now->tm_yday%7));elseweekday_nowyear_firstday=((now->tm_wday+7)-(now->tm_yday%7));// printf("%d",now->tm_yday);//今年已经过了多少天// printf("%d",now->tm_wday);//今天是星期几printf("今年第一天是星期%d\n",weekday_nowyear_firstday);}//获取用户输入的年份的第一天是星期几int firstday_weekday_inputyear(int inputyear){int weekday_inputyear_firstday;//输入年份第一天星期几time_t tval;struct tm *now;tval = time(NULL);now = localtime(&tval);if(inputyear<now->tm_year+1900){if(distance_inputyear_nowyear(inputyear,now->tm_year+1900)%7<now->tm_wday)weekday_inputyear_firstday=(now->tm_wday-distance_inputyear_nowyear(inputyear,now->tm_ year+1900)%7);elseweekday_inputyear_firstday=(now->tm_wday+7)-distance_inputyear_nowyear(inputyear,now->t m_year+1900)%7;}elseweekday_inputyear_firstday=(now->tm_wday+distance_inputyear_nowyear(inputyear,now->tm_ year+1900)%7)%7;// printf("%d",now->tm_yday);//今年已经过了多少天// printf("%d",now->tm_wday);//今天是星期几// printf("%d年第一天是星期%d\n",inputyear,weekday_inputyear_firstday);return weekday_inputyear_firstday;}//计算用户输入年份的每个月份的第一天是星期几int weekday_firstday_inputyear_month(int inputyear,int month)//month>=1{int distance_day_month=0;int weekday_month=0;switch(month){case 1:return firstday_weekday_inputyear(inputyear);break;case 2:distance_day_month=31;weekday_month=(firstday_weekday_inputyear(inputyear)+distance_day_month%7)%7;break;case 3:distance_day_month=days_month(2,inputyear)+31;weekday_month=(firstday_weekday_inputyear(inputyear)+distance_day_month%7)%7;break;case 4:distance_day_month=days_month(2,inputyear)+62;weekday_month=(firstday_weekday_inputyear(inputyear)+distance_day_month%7)%7;break;case 5:distance_day_month=days_month(2,inputyear)+92;weekday_month=(firstday_weekday_inputyear(inputyear)+distance_day_month%7)%7;break;case 6:distance_day_month=days_month(2,inputyear)+123;weekday_month=(firstday_weekday_inputyear(inputyear)+distance_day_month%7)%7;break;case 7:distance_day_month=days_month(2,inputyear)+153;weekday_month=(firstday_weekday_inputyear(inputyear)+distance_day_month%7)%7;break;case 8:distance_day_month=days_month(2,inputyear)+184;weekday_month=(firstday_weekday_inputyear(inputyear)+distance_day_month%7)%7;break;case 9:distance_day_month=days_month(2,inputyear)+215;weekday_month=(firstday_weekday_inputyear(inputyear)+distance_day_month%7)%7;break;case 10:distance_day_month=days_month(2,inputyear)+245;weekday_month=(firstday_weekday_inputyear(inputyear)+distance_day_month%7)%7;break;case 11:distance_day_month=days_month(2,inputyear)+276;weekday_month=(firstday_weekday_inputyear(inputyear)+distance_day_month%7)%7;break;case 12:distance_day_month=days_month(2,inputyear)+306;weekday_month=(firstday_weekday_inputyear(inputyear)+distance_day_month%7)%7;break;}if(weekday_month==0)return 7;return weekday_month;}void print(int year,int month){int outputNo=0; //用作记录打印出来的数字个数printf(" Sun Mon Tue Wed Thu Fri Sat \n");switch(weekday_firstday_inputyear_month(year,month)){case 7: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;}for(int i=1;i<=days_month(month,year);i++){printf("%4d",i);outputNo++;if(i!=7&&outputNo%7==0)printf("\n");if(i<=7&&(i+weekday_firstday_inputyear_month(year,month))%7==0) {printf("\n");outputNo=0;}}}int main(){int year,month,isyear=0,noyear=0,a;time_t tval;struct tm *now;tval = time(NULL);now = localtime(&tval);printf(" ******************************\n");printf(" ** 欢迎使用万年历**\n");printf(" ******************************\n");printf(" ** 制作人:秦盛伟**\n");printf(" ******************************\n");printf("请输入年份:");scanf("%d",&year);printf("请输入月份:");scanf("%d",&month);print(year,month);//打印日历printf("\n");for(int i=0;i<10;i++){printf("\n*******************************************\n");printf("是否需要再次查询?\n");printf("请输入你的选择:(1:是/2:否)");scanf("%d",&a);printf("\n*******************************************\n");if(a==1){printf("请输入年份:");scanf("%d",&year);printf("请输入月份:");scanf("%d",&month);print(year,month);}elseexit(0);}getchar();}。