简易日历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++源代码
#include "iostream"using namespace std;//#include "stdafx.h"//1900.1.1是星期1int 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;elsedays+=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;elseaa=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; }。
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万年历源代码
#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编程
#include <stdio.h>#include <stdlib.h>#include <conio.h>#define X " Sun Mon Tue Wed Thu Fri Sat"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:");}intgetday(intyear,intmonth,int date){intisleap(int year);intflag,s,i;int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};intcont=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;}intisleap(int year){if(year%4==0&&year%100||year%400==0)return 1;elsereturn 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);for(k=0;k<7-d;k++){printf("%4d",++m);}print(6);d+=a[i]%7;d%=7;print(d*4);for(k=0;k<7-d;k++){printf("%4d",++n);}printf("\n");}else{for(k=0;k<7;k++){if(m<a[i]){printf("%4d",++m);}else{print(4);}if(m==a[i]) f1=1;}print(6);for(k=0;k<7;k++){if(n<a[i+1]){printf("%4d",++n);}else{print(4);}if(n==a[i+1]) f2=1;}printf("\n");if(f1&&f2) break;}}d+=a[i+1]%7;d%=7;printf(" ");for(k=0;k<27;k++){printf("=");}print(6);printf(" ");for(k=0;k<27;k++){printf("=");}printf("\n");if(i==5){printf("Press any key to others!"); getch();system("cls");}}}void main(){int choice;intyear,month,date;intday,flag;char con;menu();scanf("%d",&choice);if(choice==1){r1:system("cls");printf("\nPlease input the year-month-date(XXXX,XX,XX):"); scanf("%d,%d,%d",&year,&month,&date);day=getday(year,month,date);if(day==0)printf("\n%d-%d-%d is Sunday!\n",year,month,date);if(day==1)printf("\n%d-%d-%d is Monday!\n",year,month,date);if(day==2)printf("\n%d-%d-%d is Tuesday!\n",year,month,date);if(day==3)printf("\n%d-%d-%d is Wednesday!\n",year,month,date);if(day==4)printf("\n%d-%d-%d is Thursday!\n",year,month,date);if(day==5)printf("\n%d-%d-%d is Friday!\n",year,month,date);if(day==6)printf("\n%d-%d-%d is Saturday!\n",year,month,date); printf("\nContinue...(Y/N)");con=getch();if((con=='y')||(con=='Y'))goto r1;if((con=='n')||(con=='N'))main();}if(choice==2){r2:system("cls");printf("\nPlease input the year(XXXX):");scanf("%d",&year);flag=isleap(year);if(flag==1)printf("\nThe year %d is leap year!\n",year);if(flag==0)printf("\nThe year %d is not leap year!\n",year);printf("\nContinue...(Y/N)");con=getch();if((con=='y')||(con=='Y'))goto r2;if((con=='n')||(con=='N'))main();}if(choice==3){r3:system("cls");printf("\nPlease input the year(XXXX):"); scanf("%d",&year);printcalendar(year);printf("Continue...(Y/N)");con=getch();if((con=='y')||(con=='Y'))goto r3;if((con=='n')||(con=='N'))main();}if(choice==4){system("cls");printf("\nDo you want to Exit?(Y/N)");con=getch();if((con=='y')||(con=='Y'))return;if((con=='n')||(con=='N'))main();}}/*【要求】:1.程序运行后,首先在屏幕上显示主菜单:1.查询某年某月某日是星期几2.查询某年是否是闰年3.打印某年的全年日历4.退出2.在主菜单中输入1后,显示:“请输入年月日(XXXX,XX,XX)”运行后输出:XXXX年XX月XX日是星期X,是否继续查询(Y/N)?如果输入Y,则重新显示“请输入年月日(XXXX,XX,XX)”,否则回到主菜单。
万年历的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>#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>//±íÍ·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程序万年历编写
C程序万年历编写#include<stdio.h>int main(){int choice;do{system("cls");printf("*********************************\n");printf("* 请选择你要的查询方式! *\n");printf("*1、输入一年的年份输出全年的日历*\n");printf("*2、输入年份、月份输出该月的日历*\n");printf("*3、输入月日,计算出该天是星期几*\n");printf("*0、Exit! *\n");printf("*********************************\n");scanf("%d",&choice);switch(choice){case 1:oneyear();system("pause");break;/*函数调用*/case 2:onemonth();system("pause");break;case 3:oneday();system("pause");break;case 0:break;}if(choice==0)break;}while(1);}/以mina()是主函数,分别对三个函数oneyear()、onemonth()、oneday()的调用/void oneyear(){int year,month, yearday,monthday,i,day,week;do{printf("请输入1980年以后的年份!\n");printf("输入你要查询的年份!\n");scanf("%d",&year);if(year<1980)printf("你输入的年份有误,请正确输入!\n");elsebreak;}while(1);for(i=1980,yearday=0; i<year; i++)/*计算所有年份的天数*/{yearday=yearday+365;if((i%4==0&&i%100!=0)||(i%400==0))/*判断闰年平年*/yearday++;}for(month=1; month<=12; month++){printf("\n%d月份\n",month);printf(" SUN MON TUE WED THU FRI SAT\n");switch(month){case 2:{if((year%4==0&&year%100!=0)||(year%400==0)) day=29;elseday=28;}break;case 4:case 6:case 9:case 11:day=30;break;default :day=31;}week=(yearday+1+1)%7;/*判断该年的一月一日是周几*/ yearday += day;for ( i = 0; i <week; ++i )printf(" ");for(monthday=1; monthday<=day; monthday++){if(week==7){printf("\n");week=0;}printf("%6d",monthday);if(monthday==day)printf("\n");week++;}}}void onemonth(){int month,day,monthday,year,yearday,totaday,i,n,week,sum;do{printf("输入1980年以后的年份!\n");printf("输入年份、月份:\n");scanf("%d,%d",&year,&month);if(year<1980)printf("你输入的有误,请重新输入!\n");elsebreak;}while(1);printf(" SUN MON TUE WED THU FRI SAT\n");yearday=0;for(i=1980; i<year; i++){yearday=yearday+365;if((i%4==0&&i%100!=0)||(i%400==0))}for(sum=0,n=1;n<month;n++){switch(n){case 2:if((year%4==0&&year%100!=0)||(year%400==0)) day=29;elseday=28;break;case 4:case 6:case 9:case 11:day=30;break;default :day=31;}sum=day+sum;}totaday=sum+yearday;week=(totaday+1+1)%7;for ( i = 0; i<week; ++i )printf(" ");switch(month){case 2:if((year%4==0&&year%100!=0)||(year%400==0))elseday=28;break;case 4:case 6:case 9:case 11:day=30;break;default :day=31;}for(monthday=1; monthday<=day; monthday++) {if(week==7){printf("\n");week=0;}printf("%6d",monthday);if(monthday==day)printf("\n");week++;}}void oneday(){int year,month,day,yearday,totaday,monthday,n,sum,i,week; do{printf("请输入1980年以后的年份!\n");printf("请输入要查询的年月日:\n");scanf("%d,%d,%d",&year,&month,&day);if(year<1980)printf("你输入的有误,请重新输入!\n");elsebreak;}while(1);yearday=0;for(i=1980;i<year;i++){yearday=365+yearday;if((i%4==0&&i%100!=0||i%400==0))yearday++;}for(sum=0,n=1;n<month;n++){switch(n){case 2:if((year%4==0&&year%100!=0)||(year%400==0)) monthday=29;elsemonthday=28;break;case 4:case 6:case 9:case 11:monthday=30;break;default :monthday=31;}sum=monthday+sum;}totaday=sum+yearday+day;week=(totaday+1)%7;switch(week){case 1:printf("该天是周一!\n");break;case 2:printf("该天是周二!\n");break;case 3:printf("该天是周三!\n");break; case 4:printf("该天是周四!\n");break; case 5:printf("该天是周五!\n");break; case 6:printf("该天是周六!\n");break; case 0:printf("该天是周日!\n");}}。
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++实现万年历源代码本⽂实例为⼤家分享了C++实现万年历的具体代码,供⼤家参考,具体内容如下#include<iostream>#include<string>#include<fstream>#include<iomanip>using namespace std;#include<time.h>ofstream fout("⽇历.txt");void Printtitle(int n);int OrEndl(int n);string Choose(); //选择功能int Calculate(int mon,int day);void Printday(int a);void FirstDay(int wday);void SomeYear(int p);void ThisMonth(); //打印当⽉⽇历的主函数void PrintFirstNum(int mon);void Printyear(int year);void ThisYear(int p); //打印当年⽇历的主函数void Month(int n);void Printnum(int q,int mon);int Firstwday[12]; //储存每个⽉1号的星期数struct tm *local;string ch;int a[12]={31,28,31,30,31,30,31,31,30,31,30,31}; //储存每⽉的天数int main(void){long t;time(&t);local=localtime(&t);local->tm_year=local->tm_year+1900;local->tm_mon++;cout<<"今天是:"<<local->tm_year<<"年"<<local->tm_mon<<"⽉"<<local->tm_mday<<"⽇,";fout<<"今天是:"<<local->tm_year<<"年"<<local->tm_mon<<"⽉"<<local->tm_mday<<"⽇,";Month(local->tm_wday);cout<<endl;fout<<endl;cout<<"当前时间是:"<<local->tm_hour<<"时"<<local->tm_min<<"分"<<local->tm_sec<<"秒"<<local->tm_wday<<endl;fout<<"当前时间是:"<<local->tm_hour<<"时"<<local->tm_min<<"分"<<local->tm_sec<<"秒"<<local->tm_wday<<endl;string flag;int sum;if(((local->tm_year%4==0)&&(local->tm_year%100!=0))||(local->tm_year%400==0))a[1]=29;sum=Calculate(local->tm_mon,local->tm_mday);int p=sum-(local->tm_wday+1)-(sum/7)*7;do{flag=Choose();if(flag=="1") //根据选择的数字确定调⽤哪个函数ThisMonth();else if(flag=="2")ThisYear(p);else if(flag=="3")SomeYear(p);else if(flag=="4")break;else{cout<<"输⼊错误"<<endl;fout<<"输⼊错误"<<endl;continue;}}while(1);cout<<"请选择"<<"1、当⽉⽇历"<<endl<<" 2、当年⽇历"<<endl <<" 3、万年历"<<endl<<" 4、退出"<<endl;fout<<"请选择"<<"1、当⽉⽇历"<<endl<<" 2、当年⽇历"<<endl <<" 3、万年历"<<endl<<" 4、退出"<<endl;cin>>ch;fout<<ch;cout<<endl;fout<<endl;return ch;}void ThisMonth(){int m=local->tm_mon%12;Printtitle(m);int p=local->tm_mday-(local->tm_wday+1)-(local->tm_mday/7)*7; Printnum(p,local->tm_mon);}void ThisYear(int p){FirstDay(p);Printyear(local->tm_year);for(int a=1;a<12;a=a+2){Printtitle(a);PrintFirstNum(a);}}void SomeYear(int p) //打印万年历的主函数{int m;cout<<"Please enter a year number"<<endl;fout<<"Please enter a year number"<<endl;while(1){scanf("%d",&m);if( m<0 ){printf("\nInput error,Please enter a year number again:\n");fflush(stdin); //没加这句话会死循环,加了就ok}else break;}fout<<m;cout<<endl;fout<<endl;Printyear(m);int n=m;if(n<local->tm_year) //计算所输年份的1⽉1⽇星期⼏{for(;n<local->tm_year;n++){if(((n%4==0)&&(n%100!=0))||(n%400==0))p=p+2;elsep++;if(p>=7)p=p-7;}}else{for(;n>local->tm_year;n--){if(((n%4==0)&&(n%100!=0))||(n%400==0))p=p-2;elsep--;if(p<0)for(int h=1;h<12;h=h+2){Printtitle(h);if(((m%4==0)&&(m%100!=0))||(m%400==0))a[1]=29;elsea[1]=28;PrintFirstNum(h);}}void Printtitle(int n) //打印标题{do{cout<<" ";fout<<" ";char str[12][10]={"January","February","March","April","May","June","July","August","September","October","November","December"}; for(int h=0;h<10;h++){cout<<str[n-1][h];fout<<str[n-1][h];}cout<<" ";fout<<" ";if(OrEndl(n))break;n++;}while(!(n%2));do{cout<<"____________________________";fout<<"____________________________";if(OrEndl(n))break;n++;}while(!(n%2));do{cout<<" Sun Mon Tue Wed Thu Fri Sat ";fout<<" Sun Mon Tue Wed Thu Fri Sat ";if(OrEndl(n))break;n++;}while(!(n%2));}int Calculate(int mon,int day) //计算当天到当年1⽉1⽇的天数{int sum=day;for(mon--;mon!=0;mon--)sum=sum+a[mon-1];return sum;}void FirstDay(int wday) //推算每个⽉1号的星期数{if(wday<=0)wday=wday+7;Firstwday[0]=7-wday;for(int n=0;n<11;n++){Firstwday[n+1]= Firstwday[n]+a[n]%7;if(Firstwday[n+1]>6)Firstwday[n+1]=Firstwday[n+1]-7;}}int OrEndl(int n){if(ch=="1") //如果是打出当⽉⽇历就直接跳出循环{cout<<endl;fout<<endl;return 1;fout<<" ";}else{cout<<endl;fout<<endl;}return 0;}void Printyear(int year) //打印年份{int m=year/1000;int n=(year/100)%10;int p=(year/10)%10;int q=year%10;int num[4]={m,n,p,q};char str[5][10][7]={"***** "," * ","***** ","***** ","* * ","***** ","***** ","***** ","***** ","***** ", "* * "," * "," * "," * ","* * ","* ","* "," * ","* * ","* * ","* * "," * ","***** ","***** ","***** ","***** ","***** "," * ","***** ","***** ","* * "," * ","* "," * "," * "," * ","* * "," * ","* * "," * ","***** "," * ","***** ","***** "," * ","***** ","***** "," * ","***** ","***** ",};for(int g=0;g<5;g++){cout<<" ";fout<<" ";for(int i=0;i<4;i++)for(int h=0;h<7;h++){cout<<str[g][num[i]][h];fout<<str[g][num[i]][h];}cout<<endl;fout<<endl;}}void PrintFirstNum(int mon) //打印每两个⽉的⽇历{int mday[2]; //储存每两个⽉当前打印的⽇期do{int k=0;for(;k<Firstwday[mon-1];k++){ cout<<" ";fout<<" ";}k++;for(int d=1;k<8;d++,k++) //输⼊每个⽉的第⼀⾏{cout<<" "<<d<<" ";fout<<" "<<d<<" ";}if(mon%2) //判断单⽉输空格,双⽉回车{cout<<" ";fout<<" ";mday[mon%2-1]=d;}else{cout<<endl;fout<<endl;mday[mon%2+1]=d-1;}mon++;}while(!(mon%2));mon=mon-2;int i=0,k=1,m=mon-1;for(;mday[i]<a[m]+1;mday[i]++,k++){if(mday[i]<10){{cout<<" "<<mday[i]<<" ";fout<<" "<<mday[i]<<" ";}if(k==7){if(!i){cout<<" ";fout<<" ";i=1;m++;}else{cout<<endl;fout<<endl;i=0;m--;}k=0;}}m=mon-1;if(mday[0]==a[m]+1&&mday[1]<a[m+1]+1) //当双⽉未结束,单⽉输⼊结束跳出时最后⼀⾏的输出情况 {for(;k<8;k++){cout<<" ";fout<<" ";}cout<<" ";fout<<" ";k=1;for(mday[1]++;mday[1]<a[m+1]+1;mday[1]++,k++){cout<<" "<<mday[1]<<" ";fout<<" "<<mday[1]<<" ";if(k==7){cout<<endl;fout<<endl;cout<<" ";fout<<" ";}}cout<<endl;fout<<endl;}if(mday[0]<a[m]+1&&mday[1]==a[m+1]+1) //当单⽉未结束,双⽉输⼊结束跳出时最后⼀⾏的输出情况 {cout<<endl;fout<<endl;k=1;for(mday[0]++;mday[0]<a[m]+1;mday[0]++,k++){cout<<" "<<mday[0]<<" ";fout<<" "<<mday[0]<<" ";if(k==7){cout<<endl;fout<<endl;cout<<" ";fout<<" ";}}cout<<endl;fout<<endl;}}void Month(int n)cout<<str[n][h];fout<<str[n][h];}}void Printnum(int q,int mon) //打印当⽉⽇历{if(q<0)q=q+7;int k=0;if(q!=7&&q){for(;k<7-q;k++){cout<<" ";fout<<" ";}}k++;for(int d=1;d<a[mon-1]+1;d++,k++){cout<<setw(4)<<d;if(k==7){cout<<endl;fout<<endl;k=0;}}cout<<endl;fout<<endl;}以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。
数字万年历简易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语⾔实现简单万年历本⽂实例为⼤家分享了C语⾔实现简单万年历的具体代码,供⼤家参考,具体内容如下1234567 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56#include <stdio.h>#include<stdlib.h>int year, month;int run[12] = { 31,29,31,30,31,30,31,31,30,31,30,31 };int ping[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };char week[7][10] = { "SUN","MON","TUE","WED","THU","FRI","SAT"}; bool IsLeap(int year){if(year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) //判断闰年 {return true;}else{return false;}}void PrintStar(){printf("\t\t\t万年历\t\t\t\n");printf("****************************************************\n");for(int i = 0; i < 7; i++){printf("%s\t", week[i]);}printf("\n");}int DaySum(int year, int month){int sum = 0;for(int i = 1990; i < year; i++){if(IsLeap(i)){sum += 366;}else{sum += 365;}}for(int i = 0; i < month - 1; i++){if(IsLeap(year)){sum += run[i];}else{sum += ping[i];}}return sum;}57585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104void PrintCal(int sum, int year, int month){int nRes, nTmp;nRes = sum % 7+1;//前⾯空⼏格nTmp = 7 - nRes;//从第⼏格开始打印 for (int i = 0; i < nRes; i++) { printf("\t");}if (IsLeap(year)){for (int i = 1; i < run[month - 1]+1; i++){ printf("%d\t", i); if (nTmp == i || (i - nTmp) % 7 == 0) { printf("\n");}} printf("\n"); } else{for (int i = 1; i < ping[month - 1]+1; i++){ printf("%d\t", i); if (nTmp == i || (i - nTmp) % 7 == 0) { printf("\n");}}printf("\n"); } }int main(void){while (1){scanf_s("%d %d", &year, &month); PrintStar(); PrintCal(DaySum(year, month), year, month); printf("****************************************************\n"); }return 0;}以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。
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语言).txt
int i; for (i=1;i<year;i++)
if ((i%4==0&&i%100!=0)||(i%400==0)) z++; for(i=1;i<month;i++)
int days_of_month(int year,int month) { int i;
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12) i=31;
else if(month==4||month==6||month==9||month==11) i=30; else if(month==2&&(year&&4==0&&year%100!=0||year%400==0)) i=29; else i=28; return i; }
int days=days_of_month(year,month); system("cls"); printf("\t\t\t\t%d 年%d 月",year,month);
printf("\n\n********************************************************************** **********\n\n");
/*VC++6.0 编译*/
#include "stdio.h"
万年历课程设计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语言万年历
源代码:完美运行#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();}。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
#include<iostream>//输入输出涵数的头文件
#include <iomanip>//对cin,cout之类的一些操纵运算子
using namespace std;
int IsLeapYear(int year); //定义一个函数,判断输入的年是不是瑞年,在此处声明这个函数void main()
{
int i;
int day;
int year;
int month;
int temp;// 临时变量我们一般把它起个名字叫做temp
int temp_i;
long int Year_days = 0;
int Year_Start = 1;
int Per_Year_Days;
int month_day[]={31,28,31,30,31,30,31,31,30,31,30,31,29};//把一年中每个月的天数存入数组,month_day[12]是闰年2月的天数
cout<<"Please enter the year: ";
cin>>year;
cout<<"Please enter the month, enter 0 for the whole year: ";
cin>>month;
while(Year_Start < year)
{
if( IsLeapYear( Year_Start ) ) //是瑞年的话一年有366天否则有365天
Per_Year_Days = 366;
else
Per_Year_Days = 365;
Year_days = Year_days + Per_Year_Days;
Year_Start++;
}
for( temp = 1; temp <=12 && (month*(temp-1)==0); temp++ ) //如果month=0,则temp从1-12循环输出,如果month!=0则只输出一次
{
if (month!=0) temp=month;
switch(temp)
{
case 1:
cout<<"("<<year<<") "<<setw(9)<<"January"<<endl; //setw()函数表示的是输出字符的宽度,
break;
case 2:
cout<<"("<<year<<") "<<setw(9)<<"February"<<endl;
break;
case 3:
cout<<"("<<year<<") "<<setw(9)<<"March"<<endl; break;
case 4:
cout<<"("<<year<<") "<<setw(9)<<"April"<<endl; break;
case 5:
cout<<"("<<year<<") "<<setw(9)<<"May"<<endl; break;
case 6:
cout<<"("<<year<<") "<<setw(9)<<"June"<<endl; break;
case 7:
cout<<"("<<year<<") "<<setw(9)<<"July"<<endl; break;
case 8:
cout<<"("<<year<<") "<<setw(9)<<"August"<<endl; break;
case 9:
cout<<"("<<year<<") "<<setw(9)<<"September"<<endl; break;
case 10:
cout<<"("<<year<<") "<<setw(9)<<"October"<<endl; break;
case 11:
cout<<"("<<year<<") "<<setw(9)<<"November"<<endl; break;
case 12:
cout<<"("<<year<<") "<<setw(9)<<"December"<<endl; break;
}
i = Year_days % 7; //判断该月开头是星期几
cout<<" Mon Tue Wed Thu Fri Sat Sun"<<endl;
if( i != 0 )//将第一天前面的几个打空格
for( temp_i = 0; temp_i < i*4; temp_i++)
cout<<" ";
day = 1;
if( IsLeapYear(year) && temp == 2) //如果是瑞年的二月
while( day <= month_day[12] ) //month_day[12] =29
{
if( day >1 )
if( Year_days % 7 == 0 )
cout<<endl;
cout<<setw(4)<<day;
Year_days++;
day++;
}
else
while (day <= month_day[temp-1]) //瑞年的二月
{
if( day > 1 )
if( Year_days % 7 == 0 )
cout<<endl;
if( day >=10 )
cout<<setw(4)<<day;
else
cout<<setw(4)<<day;
Year_days++;
day++;
}
cout<<endl;
if( getchar() == 'q' )
exit(0);
}
getchar();
}
int IsLeapYear( int year ) //定义一个函数,判断输入的年是不是瑞年,是瑞年返回1否则返回0 {
if ((year %4 == 0) && (year % 100 != 0) ||
(year % 400 == 0) ) //判定是否为闰年
return 1;
else
return 0;
}。