编写万年历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语言编写的万年历
// VC++6.0 编译通过# include <stdio.h># include <windows.h>int year; //定义年份为全局变量int check_year (int year) //判断输入的年份是否为闰年{if(year%4 == 0 && year%100 !=0 || year%400 == 0)return 1;elsereturn 0;}int check_month (int month) //判断每月的天数{switch (month){case 0: return 0; break;case 1:case 3:case 5:case 7:case 8:case 10:case 12: return 31; break;case 4:case 6:case 9:case 11: return 30; break;case 2: //闰年二月和平年二月的天数{if (check_year(year) == 1)return 29;elsereturn 28;} break;}}int firstday (int year,int month) //判断某年某月的第一天为星期几{static int w=0;w += check_month(month-1);return ((year-1)+((year-1)/4)-((year-1)/100)+((year-1)/400)+1+w)%7;}main (){int month=1,day,i,flag;printf ("请输入要打印的年份: ");scanf ("%d",&year);printf ("\n");printf (" %d年\n\n",year);for (month=1;month<=12;month++){printf (" %d月\n",month);printf (" ---------------------------\n");printf (" SUN MON TUE WED THU FRI SET\n");printf (" ---------------------------\n");flag = firstday(year,month);for (i=0;i<flag;i++) //每月第一天所在星期几之前的位置用空格输出printf (" ");for (day=1;day<=check_month(month);day++) //按格式输出日历{printf ("%4d",day);if ((day+flag)%7 == 0)printf ("\n");}printf("\n\n");system("pause");printf("\n");}}。
C语言万年历代码
题目:年历显示。
功能要求:(1)输入一个年份,输出是在屏幕上显示该年的日历。
假定输入的年份在1940-2040年之间。
(2)输入年月,输出该月的日历。
(3)输入年月日,输出距今天还有多少天,星期几,是否是公历节日。
如下图:以下部分为代码:#include<stdio.h>#include<math.h>void part1(int x); //函数1~6为打印日历的函数void part2(int x);void part3(int x);void part4(int x);void part5(int x);void part6(int x);int weak(int x,int y); //计算1号对应的星期int weak2(int x,int y,int z); //计算星期,为函数day提供数据int year(int x); //打印日历的函数int mouth(int x); //打印月历的函数int day(int x); //查询天数的函数int distance(int x,int y,int z); //提供距离天数查询int main(){int a;char z;printf("****************************************************************\n");printf(" * *\n");printf(" * *\n");printf(" * *\n");printf(" * 欢迎使用万年历!*\n");printf(" * *\n");printf(" * *\n");printf(" * 开发:杨润*\n");printf("****************************************************************\n");x: //位置标注printf("\n");printf("请输入一个日期(Ex:20150302或201503或2015):");scanf("%d",&a);printf("\n");if((1940<=a)&&(a<=2040)){year(a);}else if((194001<=a)&&(a<=204012)){mouth(a);}else if((19400101<=a)&&(a<=20401231)){day(a);}else{printf("输入错误,请重新输入!");goto x;}printf("\n");printf("\n");printf("继续查询(y),退出(n):");scanf("%s",&z);if(z=='y'){goto x;}else{;}return 0;}int year(int x){printf("-------------------------------%d年的年历----------------------------\n",x);printf("\n");part1(x); //调用第一部分函数part2(x);part3(x);part4(x);part5(x);part6(x);printf("-----------------------------------------------------------------------\n");return 0;}int mouth(int x){int i,n,y,y2,w,week,yue2,bz1; //n表示年份,y表示月份,w,y2均为临时变量,yue2表示2月份天数n=(int)(x/100);y=(int)(x%100);printf("您现在查询的是%d年%d月\n",n,y);printf(" \n");if(y==1) //1月的情况{printf("1月Sun Mon Tue Wed Thu Fri Sat\n");printf(" ");if(n<2000) //计算小于两千的1.1星期{y2=(n-1)%100; //y2 w=(int)(y2+(y2/4)+(19/4)-38+(26*1.4));week=w%7;}if(n>=2000) //计算大于两千的1.1星期{ y2=(n-1)%100;w=(int)(y2+(y2/4)+(20/4)-40+(26*1.4));week=w%7;}for(i=0;i<week;i++){printf(" ");}bz1=1;for(i=0;i<(7-week);i++) //第一行的一月份{if(bz1<10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第二行的1月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第三行的1月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第四行的1月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第五行的1月份for(i=0;i<7;i++){if(bz1<=31){printf(" %d ",bz1);}if(bz1>31){printf(" ");}bz1=bz1+1;}printf("\n");printf(" "); //第六行的1月份for(i=0;i<7;i++){if(bz1<=31){printf(" %d ",bz1);}if(bz1>31){printf(" ");}bz1=bz1+1;}printf("\n");}if(y==2) //2月的情况{if(n%4==0){if(n%100!=0)yue2=29;else if(n%100==0&&n%400==0)yue2=29;elseyue2=28;}else{yue2=28;}printf("2月Sun Mon Tue Wed Thu Fri Sat\n");printf(" ");if(n<2000) //计算小于两千的2.1星期{y2=(n-1)%100; //y2w=(int)(y2+(y2/4)+(19/4)-38+(26*1.5));week=w%7;}if(n>=2000) //计算大于两千的2.1星期{ y2=(n-1)%100;w=(int)(y2+(y2/4)+(20/4)-40+(26*1.5));week=w%7;}for(i=0;i<week;i++){printf(" ");}bz1=1;for(i=0;i<(7-week);i++) //第一行的2月份{if(bz1<10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第二行的2月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第三行的2月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第四行的2月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第五行的2月份for(i=0;i<7;i++){if(bz1<=yue2){printf(" %d ",bz1);}if(bz1>yue2){printf(" ");}bz1=bz1+1;}printf("\n");printf(" "); //第六行的2月份for(i=0;i<7;i++){if(bz1<=yue2){printf(" %d ",bz1);}if(bz1=yue2){printf(" ");}bz1=bz1+1;}printf("\n");}//2月情况判断完毕if((y==3)||(y==5)||(y==7)||(y==8)||(y==10)||(y==12)) //31天的情况(3、5、7、8、10、12月){printf("%d月Sun Mon Tue Wed Thu Fri Sat\n",y);printf(" ");week=weak(n,y);for(i=0;i<week;i++) //第一行{printf(" ");}bz1=1;for(i=0;i<(7-week);i++){if(bz1<10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第二行for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第三行for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第四行for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第五行for(i=0;i<7;i++){if(bz1<=31){printf(" %d ",bz1);}if(bz1>31){printf(" ");}bz1=bz1+1;}printf("\n");printf(" "); //第六行for(i=0;i<7;i++){if(bz1<=31){printf(" %d ",bz1);}if(bz1>31){printf(" ");}bz1=bz1+1;}printf("\n");}if((y==4)||(y==6)||(y==9)||(y==11)) //30天的情况(4、6、9、11月){printf("%d月Sun Mon Tue Wed Thu Fri Sat\n",y);printf(" ");week=weak(n,y);for(i=0;i<week;i++) //第一行{printf(" ");}bz1=1;for(i=0;i<(7-week);i++){if(bz1<10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第二行for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第三行for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第四行for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf("\n");printf(" "); //第五行for(i=0;i<7;i++){if(bz1<=30){printf(" %d ",bz1);}if(bz1>30){printf(" ");}bz1=bz1+1;}printf("\n");printf(" "); //第六行for(i=0;i<7;i++){if(bz1<=30){printf(" %d ",bz1);}if(bz1>30){printf(" ");}bz1=bz1+1;}printf("\n");}return 0;}int day(int x){int n,y,y1,t,week; //n为年,y为yue,y1位计算y的临时变量,t为天,week为周,p为距离今天天数n=x/10000;y1=x%10000;y=y1/100;t=x%100;printf("\n");printf("您查询的是:%d年%d月%d日",n,y,t);week=weak2(n,y,t);switch(week) //根据返回数值判断星期{case 0:printf("星期日");break;case 1:printf("星期一");break;case 2:printf("星期二");break;case 3:printf("星期三");break;case 4:printf("星期四");break;case 5:printf("星期五");break;case 6:printf("星期六");break;}if(y==1&&t==1) printf("这天是元旦"); //查询节日if(y==2&&t==2) printf("这天是世界湿地日");if(y==2&&t==14) printf("这天是情人节");if(y==3&&t==3) printf("这天是全国爱耳日");if(y==3&&t==5) printf("这天是青年志愿者服务日");if(y==3&&t==8) printf("这天是国际妇女节");if(y==3&&t==9) printf("这天是保护母亲河日");if(y==3&&t==12) printf("这天是中国植树节");if(y==3&&t==14) printf("这天是白色情人节\n");if(y==3&&t==14) printf("这天是国际警察日");if(y==3&&t==15) printf("这天是世界消费者权益日");if(y==3&&t==21) printf("这天是世界森林日\n");if(y==3&&t==21) printf("这天是世界睡眠日");if(y==3&&t==22) printf("这天是世界水日");if(y==3&&t==23) printf("这天是世界气象日");if(y==3&&t==24) printf("这天是世界防治结核病日");if(y==4&&t==1) printf("这天是愚人节");if(y==4&&t==5) printf("这天是清明节");if(y==4&&t==7) printf("这天是世界卫生日");if(y==4&&t==22) printf("这天是世界地球日");if(y==4&&t==26) printf("这天是世界知识产权日");if(y==5&&t==1) printf("这天是国际劳动节");if(y==5&&t==3) printf("这天是世界哮喘日");if(y==5&&t==4) printf("这天是中国青年节");if(y==5&&t==8) printf("这天是世界红十字日");if(y==5&&t==12) printf("这天是国际护士节");if(y==5&&t==15) printf("这天是国际家庭日");if(y==5&&t==17) printf("这天是世界电信日");if(y==5&&t==20) printf("这天是全国学生营养日");if(y==5&&t==23) printf("这天是国际牛奶日");if(y==5&&t==31) printf("这天是世界无烟日");if(y==6&&t==1) printf("这天是国际儿童节");if(y==6&&t==5) printf("这天是世界环境日");if(y==6&&t==6) printf("这天是全国爱眼日");if(y==6&&t==17) printf("这天是世界防治荒漠化和干旱日"); if(y==6&&t==23) printf("这天是国际奥林匹克日");if(y==6&&t==25) printf("这天是全国土地日");if(y==6&&t==26) printf("这天是国际禁毒日");if(y==7&&t==1) printf("这天是中国共产党诞生日\n");if(y==7&&t==1) printf("这天是国际建筑日");if(y==7&&t==7) printf("这天是中国人民抗日战争纪念日"); if(y==7&&t==11) printf("这天是世界人口日");if(y==8&&t==1) printf("这天是中国人民解放军建军节");if(y==8&&t==12) printf("这天是国际青年节");if(y==9&&t==8) printf("这天是国际扫盲日");if(y==9&&t==10) printf("这天是中国教师节");if(y==9&&t==16) printf("这天是中国脑健康日\n");if(y==9&&t==16) printf("这天是国际臭氧层保护日");if(y==9&&t==20) printf("这天是全国爱牙日");if(y==9&&t==21) printf("这天是世界停火日");if(y==9&&t==27) printf("这天是世界旅游日");if(y==10&&t==1) printf("这天是中华人民共和国国庆节\n");if(y==10&&t==1) printf("这天是国际音乐日\n");if(y==10&&t==1) printf("这天是国际老年人日");if(y==10&&t==4) printf("这天是世界动物日");if(y==10&&t==5) printf("这天是世界教师日");if(y==10&&t==8) printf("这天是全国高血压日");if(y==10&&t==9) printf("这天是世界邮政日");if(y==10&&t==10) printf("这天是世界精神卫生日");if(y==10&&t==14) printf("这天是世界标准日");if(y==10&&t==15) printf("这天是国际盲人节\n");if(y==10&&t==15) printf("这天是世界农村妇女日");if(y==10&&t==16) printf("这天是世界粮食日");if(y==10&&t==17) printf("这天是国际消除贫困日");if(y==10&&t==24) printf("这天是联合国日\n");if(y==10&&t==24) printf("这天是世界发展新闻日");if(y==10&&t==28) printf("这天是中国男性健康日");if(y==10&&t==29) printf("这天是国际生物多样性日");if(y==10&&t==31) printf("这天是万圣节");if(y==11&&t==8) printf("这天是中国记者节");if(y==11&&t==9) printf("这天是消防宣传日");if(y==11&&t==14) printf("这天是世界糖尿病日");if(y==11&&t==17) printf("这天是国际大学生节");if(y==11&&t==25) printf("这天是国际消除对妇女的暴力日");if(y==12&&t==1) printf("这天是世界爱滋病日");if(y==12&&t==3) printf("这天是世界残疾人日");if(y==12&&t==4) printf("这天是全国法制宣传日");if(y==12&&t==9) printf("这天是世界足球日");if(y==12&&t==25) printf("这天是圣诞节");if(y==12&&t==29) printf("这天是国际生物多样性日");printf("\n");distance(n,y,t);return 0;}//计算今天日期的函数结尾void part1(int x) //第一部分{int i,week,week2,y,w,b1,bz1,bz2;//week,week2用于计算1.1的星期,bz1和bz2为日期的递增b1=7;printf("1月Sun Mon Tue Wed Thu Fri Sat");printf(" ");printf("7月Sun Mon Tue Wed Thu Fri Sat\n");printf(" ");if(x<2000) //计算小于两千的1.1星期{ y=(x-1)%100;w=(int)(y+(y/4)+(19/4)-38+(26*1.4));week=w%7;}if(x>=2000) //计算大于两千的1.1星期{ y=(x-1)%100;w=(int)(y+(y/4)+(20/4)-40+(26*1.4));week=w%7;}week2=weak(x,b1); //调用计算星期的函数(7.1) for(i=0;i<week;i++){printf(" ");}bz1=1,bz2=1;for(i=0;i<(7-week);i++){if(bz1<10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印7月的for(i=0;i<=week2;i++){printf(" ");}for(i=0;i<(7-week2);i++){if(bz2<10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第一行打印完毕printf(" "); //第二行的1月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印7月的第二行for(i=0;i<7;i++){if(bz2<10){printf(" %d ",bz2);}if(bz2>=10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第二行打印结束printf(" "); //第三行的1月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印7月的第三行for(i=0;i<7;i++){ if(bz2<10){printf(" %d ",bz2);}if(bz2>=10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第三行打印结束printf(" "); //第四行的1月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印7月的第四行for(i=0;i<7;i++){if(bz2<10){printf(" %d ",bz2);}if(bz2>=10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第四行打印结束printf(" "); //第五行的1月份for(i=0;i<7;i++){if(bz1<=31){printf(" %d ",bz1);}if(bz1>31){printf(" ");}bz1=bz1+1;}printf(" "); //从这里开始打印7月的第五行for(i=0;i<7;i++){if(bz2<=31){printf(" %d ",bz2);}if(bz2>31){printf(" ");}bz2=bz2+1;}printf("\n"); //第五行打印结束printf(" "); //第六行的1月份for(i=0;i<7;i++){if(bz1<=31){printf(" %d ",bz1);}if(bz1>31){printf(" ");}bz1=bz1+1;}printf(" "); //从这里开始打印7月的第六行for(i=0;i<7;i++){if(bz2<=31){printf(" %d ",bz2);}if(bz2>31){printf(" ");}bz2=bz2+1;}printf("\n"); //第六行打印结束} //第一部分1月、7月打印完毕!void part2(int x) //第二部分2月、8月开始打印!//第二部分{int i,week,week2,y,w,b1,bz1,bz2,yue2;//week,week2用于计算2.1的星期,bz1和bz2为日期的递增b1=8; //表示当前部分的月份printf("2月Sun Mon Tue Wed Thu Fri Sat");printf(" ");printf("8月Sun Mon Tue Wed Thu Fri Sat\n");printf(" ");if(x%4==0){if(x%100!=0)yue2=29;else if(x%100==0&&x%400==0)yue2=29;elseyue2=28;}else{yue2=28;}if(x<2000) //计算小于两千的1.1星期{ y=(x-1)%100;w=(int)(y+(y/4)+(19/4)-38+(26*1.5));week=w%7;}if(x>=2000) //计算大于两千的1.1星期{ y=(x-1)%100;w=(int)(y+(y/4)+(20/4)-40+(26*1.5));week=w%7;}week2=weak(x,b1); //调用计算星期的函数(7.1) for(i=0;i<week;i++){printf(" ");}bz1=1,bz2=1;for(i=0;i<(7-week);i++){if(bz1<10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印8月的第一行for(i=0;i<=week2;i++){printf(" ");}for(i=0;i<(7-week2);i++){if(bz2<10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第一行打印完毕printf(" "); //2月份的第二行for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印8月的第二行for(i=0;i<7;i++){if(bz2<10){printf(" %d ",bz2);}if(bz2>=10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第二行打印结束printf(" "); //第三行的2月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印8月的第三行for(i=0;i<7;i++){ if(bz2<10){printf(" %d ",bz2);}if(bz2>=10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第三行打印结束printf(" "); //第四行的2月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印8月的第四行for(i=0;i<7;i++){if(bz2<10){printf(" %d ",bz2);}if(bz2>=10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第四行打印结束printf(" "); //第五行的2月份for(i=0;i<7;i++){if(bz1<=yue2){printf(" %d ",bz1);}if(bz1>yue2){printf(" ");}bz1=bz1+1;}printf(" "); //从这里开始打印8月的第五行for(i=0;i<7;i++){if(bz2<=31){printf(" %d ",bz2);}if(bz2>31){printf(" ");}bz2=bz2+1;}printf("\n"); //第五行打印结束printf(" "); //第六行的2月份for(i=0;i<7;i++){if(bz1<=yue2){printf(" %d ",bz1);}if(bz1>yue2){printf(" ");}bz1=bz1+1;}printf(" "); //从这里开始打印8月的第六行for(i=0;i<7;i++){if(bz2<=31){printf(" %d ",bz2);}if(bz2>31){printf(" ");}bz2=bz2+1;}printf("\n"); //第六行打印结束}void part3(int x) //第三部分{int i,week,week2,a1,b1,bz1,bz2;//week,week2用于计算1.1的星期,bz1和bz2为日期的递增a1=3,b1=9; //表示当前不封的月份printf("3月Sun Mon Tue Wed Thu Fri Sat");printf(" ");printf("9月Sun Mon Tue Wed Thu Fri Sat\n");printf(" ");week=weak(x,a1); //调用计算星期的函数(3.1)week2=weak(x,b1); //调用计算星期的函数(8.1)for(i=0;i<week;i++){printf(" ");}bz1=1,bz2=1;for(i=0;i<(7-week);i++){if(bz1<10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印9月的for(i=0;i<=week2;i++){printf(" ");}for(i=0;i<(7-week2);i++){if(bz2<10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第一行打印完毕printf(" "); //第二行的3月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印9月的第二行for(i=0;i<7;i++){if(bz2<10){printf(" %d ",bz2);}if(bz2>=10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第二行打印结束printf(" "); //第三行的3月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印9月的第三行for(i=0;i<7;i++){ if(bz2<10){printf(" %d ",bz2);}if(bz2>=10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第三行打印结束printf(" "); //第四行的3月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印9月的第四行for(i=0;i<7;i++){if(bz2<10){printf(" %d ",bz2);}if(bz2>=10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第四行打印结束printf(" "); //第五行的3月份for(i=0;i<7;i++){if(bz1<=31){printf(" %d ",bz1);}if(bz1>31){printf(" ");}bz1=bz1+1;}printf(" "); //从这里开始打印9月的第五行for(i=0;i<7;i++){if(bz2<=30){printf(" %d ",bz2);}if(bz2>30){printf(" ");}bz2=bz2+1;}printf("\n"); //第五行打印结束printf(" "); //第六行的3月份for(i=0;i<7;i++){if(bz1<=31){printf(" %d ",bz1);}if(bz1>31){printf(" ");}bz1=bz1+1;}printf(" "); //从这里开始打印9月的第六行for(i=0;i<7;i++){if(bz2<=30){printf(" %d ",bz2);}if(bz2>30){printf(" ");}bz2=bz2+1;}printf("\n"); //第六行打印结束}void part4(int x) //第四部分{int i,week,week2,a1,b1,bz1,bz2;//week,week2用于计算1.1的星期,bz1和bz2为日期的递增a1=4,b1=10; //表示当前不封的月份printf("4月Sun Mon Tue Wed Thu Fri Sat");printf(" ");printf("10月Sun Mon Tue Wed Thu Fri Sat\n");printf(" ");week=weak(x,a1); //调用计算星期的函数(4.1)week2=weak(x,b1); //调用计算星期的函数(10.1)for(i=0;i<week;i++){printf(" ");}bz1=1,bz2=1;for(i=0;i<(7-week);i++){if(bz1<10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印4月的for(i=0;i<=week2;i++){printf(" ");}for(i=0;i<(7-week2);i++){if(bz2<10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第一行打印完毕printf(" "); //第二行的4月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印10月的第二行for(i=0;i<7;i++){if(bz2<10){printf(" %d ",bz2);}if(bz2>=10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第二行打印结束printf(" "); //第三行的4月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印10月的第三行for(i=0;i<7;i++){ if(bz2<10){printf(" %d ",bz2);}if(bz2>=10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第三行打印结束printf(" "); //第四行的4月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印10月的第四行for(i=0;i<7;i++){if(bz2<10){printf(" %d ",bz2);}if(bz2>=10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第四行打印结束printf(" "); //第五行的10月份for(i=0;i<7;i++){if(bz1<=30){printf(" %d ",bz1);}if(bz1>30){printf(" ");}bz1=bz1+1;}printf(" "); //从这里开始打印10月的第五行for(i=0;i<7;i++){if(bz2<=31){printf(" %d ",bz2);}if(bz2>31){printf(" ");}bz2=bz2+1;}printf("\n"); //第五行打印结束printf(" "); //第六行的4月份for(i=0;i<7;i++){if(bz1<=30){printf(" %d ",bz1);}if(bz1>30){printf(" ");}bz1=bz1+1;}printf(" "); //从这里开始打印10月的第六行for(i=0;i<7;i++){if(bz2<=31){printf(" %d ",bz2);}if(bz2>31){printf(" ");}bz2=bz2+1;}printf("\n"); //第六行打印结束}void part5(int x) //第五部分{int i,week,week2,a1,b1,bz1,bz2;//week,week2用于计算1.1的星期,bz1和bz2为日期的递增a1=5,b1=11; //表示当前不封的月份printf("5月Sun Mon Tue Wed Thu Fri Sat");printf(" ");printf("11月Sun Mon Tue Wed Thu Fri Sat\n");printf(" ");week=weak(x,a1);week2=weak(x,b1); //调用计算星期的函数(11.1)for(i=0;i<week;i++){printf(" ");}bz1=1,bz2=1;for(i=0;i<(7-week);i++){if(bz1<10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印11月的for(i=0;i<=week2;i++){printf(" ");}for(i=0;i<(7-week2);i++){if(bz2<10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第一行打印完毕printf(" "); //第二行的5月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印11月的第二行for(i=0;i<7;i++){if(bz2<10){printf(" %d ",bz2);}if(bz2>=10)bz2=bz2+1;}printf("\n"); //第二行打印结束printf(" "); //第三行的5月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印11月的第三行for(i=0;i<7;i++){ if(bz2<10){printf(" %d ",bz2);}if(bz2>=10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第三行打印结束printf(" "); //第四行的5月份for(i=0;i<7;i++){ if(bz1<10){printf(" %d ",bz1);}if(bz1>=10){printf(" %d ",bz1);}bz1=bz1+1;}printf(" "); //从这里开始打印11月的第四行for(i=0;i<7;i++){if(bz2<10){printf(" %d ",bz2);}if(bz2>=10){printf(" %d ",bz2);}bz2=bz2+1;}printf("\n"); //第四行打印结束printf(" "); //第五行的5月份for(i=0;i<7;i++){if(bz1<=31){printf(" %d ",bz1);}if(bz1>31)bz1=bz1+1;}printf(" "); //从这里开始打印11月的第五行for(i=0;i<7;i++){if(bz2<=30){printf(" %d ",bz2);}if(bz2>30){printf(" ");}bz2=bz2+1;}printf("\n"); //第五行打印结束printf(" "); //第六行的5月份for(i=0;i<7;i++){if(bz1<=31){printf(" %d ",bz1);}if(bz1>31){printf(" ");}bz1=bz1+1;}printf(" "); //从这里开始打印11月的第六行for(i=0;i<7;i++){if(bz2<=30){printf(" %d ",bz2);}if(bz2>30){printf(" ");}bz2=bz2+1;}printf("\n"); //第六行打印结束}void part6(int x) //第六部分{int i,week,week2,a1,b1,bz1,bz2;//week,week2用于计算1.1的星期,bz1和bz2为日期的递增a1=6,b1=12; //表示当前不封的月份printf("6月Sun Mon Tue Wed Thu Fri Sat");printf(" ");printf("12月Sun Mon Tue Wed Thu Fri Sat\n");printf(" ");week=weak(x,a1);week2=weak(x,b1); //调用计算星期的函数(12.1)for(i=0;i<week;i++){printf(" ");}。
c语言万年历程序
#include <stdio.h>#include <stdlib.h>#include <ctype.h>int leap (int year) ;//判断是否为闰年int days_month (int month,int year) ;//判断这个月的天数int menu_select();/*void f(){int day,month,year,sum,leap,S;printf("\n请输入年月日\n");scanf("%d%d%d",&year,&month,&day);switch(month){case 1:sum=0;break;case 2:sum=31;break;case 3:sum=59;break;case 4:sum=90;break;case 5:sum=120;break;case 6:sum=151;break;case 7:sum=181;break;case 8:sum=212;break;case 9:sum=243;break;case 10:sum=273;break;case 11:sum=304;break;case 12:sum=334;break;default:printf("data error");break;}sum=sum+day;if(year%400==0||(year%4==0&&year%100!=0))leap=1;else leap=0;if(leap==1&&month>2)sum++;S=(year-1+(year-1)/4-(year-1)/100+(year-1)/400+sum)%7; //X表示年份,C是该年份元旦开始到这一日的天数//S/7的系数就是星期数//01printf("%d",S);switch(S){case 1:printf("星期一\n");break;case 2:printf("星期二\n");break;case 3:printf("星期三\n");break;case 4:printf("星期四\n");break;case 5:printf("星期五\n");break;case 6:printf("星期六\n");break;case 0:printf("星期日\n");break;}}*/int Leap(int year){ int leap;if(year%400==0||(year%4==0&&year%100!=0))leap=1;else leap=0;return leap;}int SU(int sum,int year){int S;S=(year-1+(year-1)/4-(year-1)/100+(year-1)/400+sum)%7;return S;}int Sum(int year,int month,int day=1){int sum,leap;switch(month){case 1:sum=0;break;case 2:sum=31;break;case 3:sum=59;break;case 4:sum=90;break;case 5:sum=120;break;case 6:sum=151;break;case 7:sum=181;break;case 8:sum=212;break;case 9:sum=243;break;case 10:sum=273;break;case 11:sum=304;break;case 12:sum=334;break;default:printf("data error");break;}sum=sum+day;leap=Leap(year);if(leap==1&&month>2)sum++;return sum;}void Print(int S){switch(S){case 1:printf("星期一\n");break;case 2:printf("星期二\n");break;case 3:printf("星期三\n");break;case 4:printf("星期四\n");break;case 5:printf("星期五\n");break;case 6:printf("星期六\n");break;case 0:printf("星期日\n");break;}}void Fun1(){int day,month,year,sum,S;printf("\n请输入年月日\n");scanf("%d%d%d",&year,&month,&day);sum=Sum(year,month,day);S=SU(sum,year);Print(S);}void Fun2(){int i,j=1,k=1,a,b,month,year,sum;printf("\n 输入年月:\n");scanf("%d%d",&year,&month);b=days_month(month,year);sum=Sum(year,month);a=SU(sum,year);printf("*************************************\n");printf(" Sun Mon Tue Wed Thu Fri Sat \n");if(a==7){for(i=1;i<=b;i++){printf("%4d",i);if(i%7==0){printf("\n");}}}if(a!=7){while (j<=4*a){printf(" ");j++;}for(i=1;i<=b;i++){printf("%4d",i);if(i==7*k-a){printf("\n");k++;}}}printf("\n*************************************\n");printf("\n");}int days_month (int month,int year){if(month==1||month==3||month==5||month==7||month==8||month==10||month==12) return 31;if(month==4||month==6||month==9||month==11)return 30;if(month==2&&Leap(year)==1) return 29;else return 28;}void main(){for(;;){switch(menu_select()){case 1:printf("输入年月日计算该月第一天是星期几\n");Fun1();break;case 2:printf("打印任意日历\n");Fun2();break;case 3:printf("谢谢使用!\n");exit(0);}}}int menu_select(){ system("cls");char s;int cn;printf("1. 输入年月日计算该月第一天是星期几\n");printf("2. 打印任意日历\n");printf("3.谢谢使用! \n");printf("input 1-3:");do {s=getchar();cn=(int)s-48;}while(cn<0||cn>6);return cn;}。
C语言的万年历
int month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; int day1=0,m1=0;
if(m>1&&m<=12) {
for(m1=1;m1<m;m1++) day1+=month[m1];
day1=day1+d; } else if(m=1)
} d1=y*Y+count; eek(int d) { switch(d%7) { case 0: printf("Sunday\n");break; case 1: printf("Monday\n");break; case 2: printf("Tuesday\n");break; case 3: printf("Wednesday\n");break; case 4: printf("Thursday\n");break; case 5: printf("Friaday\n");break; case 6: printf("Saturday\n");break; }
最近准备毕业设计,难啊。一时无聊,用 C 写了一个万年历,放到这来,让喜爱编程的朋友交流下, 希望大家多指点! 此万年历只供大家交流,请勿为了应付作业直接 COPY!
这个万年历的主要思想就是找到输入年份的距离公元 0 年 1 月 1 日的天数,我将这一天定义为了 被认为是一周的开始——星期天,如果你不喜欢这么定义,可以自己更改!不过貌似现在的电子日 历都是讲公元 0 年 1 月 1 日定为星期天的,为了和世界接轨,还是别改了!哈哈!
c语言万年历
c语言万年历#include<stdio.h>main(){for(;;){int nian,yue,a,b,m,c,_m=28;long e;printf("请输入年份:");scanf("%d",&nian);e=nian;e=e-1;e=(e*365+e/4)%7;m=e;if((nian%4==0)||(nian%100==0)&&(nian%400!=0)) //求出nian是否为闰年//m++;printf("%d的日历:",nian);for(yue=1;yue<=12;yue++){if(yue==1||yue==3||yue==5||yue==7||yue==8||yue==10||yue==12){c=0;printf("\n");printf(" %d月\n",yue);printf(" 日一二三四五六\n");for(b=1;b<=m;b++){c++;printf(" ");}for(a=1;a<=31;a++){c++;if(c%7-1==0&&c!=1)printf("\n");if(a<10)printf(" ");printf(" %d ",a);m++;if(m==7)m=0;}printf("\n");}else{if(yue==4||yue==6||yue==9||yue==11||yue==2){if(yue==2){c=0;printf("\n");printf(" %d月\n",yue);printf(" 日一二三四五六\n");for(b=1;b<=m;b++){c++;printf(" ");}for(a=1;a<=_m;a++){c++;if(c%7-1==0&&c!=1)printf("\n");if(a<10)printf(" ");printf(" %d ",a);m++;if(m==7)m=0;}printf("\n");}else{c=0;printf("\n");printf(" %d月\n",yue);printf(" 日一二三四五六\n");for(b=1;b<=m;b++){c++;printf(" ");}for(a=1;a<=30;a++){c++;if(c%7-1==0&&c!=1)printf("\n");if(a<10)printf(" ");printf(" %d ",a);m++;if(m==7)m=0;}printf("\n");} } }} } }。
万年历C编程
#include <stdio.h>#include <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语言源程序
#include <stdio.h>#include <windows.h>#include <wincon.h>#include<string.h>#include<stdlib.h>#include<conio.h>#include<time.h>#include<math.h>#define NULL 0CONSOLE_SCREEN_BUFFER_INFO csbiInfo; extern WINBASEAPI HWND WINAPI GetConsoleWindow(); time_t T;struct tm * now;int min,sec;int hour,nowyear,nowmonth,nowday;void ti2(){time ( &T );now = localtime ( &T );hour=now->tm_hour%12;min=now->tm_min-15;sec=now->tm_sec-15;}void ti(){time ( &T );now = localtime ( &T );hour=now->tm_hour;min=now->tm_min;sec=now->tm_sec;nowyear=now->tm_year+1900;nowmonth=now->tm_mon+1;nowday=now->tm_mday;}int yearbak=0;void clock_sz();int pd( int year);void huizs(int line_head_month);void hzdy(int year,int nowmonth_hz);void menu();void clear();int main(int argc, char* argv[]){int x=0;ti();clock_sz();hzdy(nowyear,nowmonth);menu();return 0;}void clear(){int i;HWND hwnd;HANDLE hOut;HDC hdc;HBRUSH hbr;COORD pos={1,4};hwnd=GetConsoleWindow();hdc = GetDC(hwnd);hOut = GetStdHandle(STD_OUTPUT_HANDLE);hbr= CreateSolidBrush(RGB(0,0,0));SelectObject(hdc,hbr);Rectangle(hdc,0,65,670,470);SetConsoleCursorPosition(hOut, pos);for(i=0;i<10;i++)printf(" \n ");SetConsoleCursorPosition(hOut, pos);Rectangle(hdc,0,65,670,470);ReleaseDC(hwnd, hdc);}void menu(){int year=0,xyear=0,x, xy=0,i ;struct re{int top;int left;int right;int bottom;}rt[13];HWND hwnd;HDC hdc,dc;HBRUSH hbr;COORD pos3_1 = {1, 4},pos3_2= {1, 1},pos = {1, 4},pos2_3 = {1, 6},pos2_4 = {1, 7};INPUT_RECORD mouseRec;DWORD state = 0, res=0;POINT pt;HPEN pn;HANDLE hOut, hIn;hwnd=GetConsoleWindow();//得到控制台窗口句柄hdc = GetDC(hwnd); //得到画图设备句柄dc = GetDC(hwnd);//画刷hbr= CreateSolidBrush(RGB(255,0,0));SelectObject(dc,hbr);for(rt[1].left=20,i=2;i<=12;i++) rt[i].left=rt[i-1].left+50;for(rt[1].right=50,i=2;i<=12;i++) rt[i].right=rt[i-1].right+50; //定位按钮for(i=0;i<=12;i++) rt[i].top=40;for(i=0;i<=12;i++) rt[i].bottom=60;hOut = GetStdHandle(STD_OUTPUT_HANDLE);hIn=GetStdHandle(STD_INPUT_HANDLE);pn=CreatePen(PS_SOLID,1,RGB(255,0,255));GetClientRect(hwnd, &rt);SelectObject(hdc, pn);SetBkMode(hdc,TRANSPARENT);MoveToEx(hdc,1,35,NULL);LineTo(hdc,620,35);LineTo(hdc,620,62);LineTo(hdc,1,62);LineTo(hdc,1,35);pn=CreatePen(PS_SOLID,2,RGB(255,255,0));SelectObject(hdc, pn);MoveToEx(hdc,5,75,NULL);LineTo(hdc,45,75);hbr= CreateSolidBrush(RGB(0,0,190));SelectObject(dc,hbr);for(i=1;i<=12;i++)Rectangle(dc,rt[i].left,rt[i].top,rt[i].right,rt[i].bottom);SetTextColor(hdc,RGB(0,255,255));TextOut(hdc,280,10,TEXT("万年历"),6);//输出文本SetTextColor(hdc,RGB(255,255,0));////设颜色TextOut(hdc,rt[1].left,rt[1].top,TEXT(" 1"),3);//输出文本TextOut(hdc,rt[1].left+=50,rt[1].top,TEXT(" 2"),3);//输出文本TextOut(hdc,rt[1].left+=50,rt[1].top,TEXT(" 3"),3);//输出文本TextOut(hdc,rt[1].left+=50,rt[1].top,TEXT(" 4"),3);//输出文本TextOut(hdc,rt[1].left+=50,rt[1].top,TEXT(" 5"),3);//输出文本TextOut(hdc,rt[1].left+=50,rt[1].top,TEXT(" 6"),3);//输出文本TextOut(hdc,rt[1].left+=50,rt[1].top,TEXT(" 7"),3);//输出文本TextOut(hdc,rt[1].left+=50,rt[1].top,TEXT(" 8"),3);//输出文本TextOut(hdc,rt[1].left+=50,rt[1].top,TEXT(" 9"),3);//输出文本TextOut(hdc,rt[1].left+=50,rt[1].top,TEXT(" 0"),3);//输出文本TextOut(hdc,rt[1].left+=50,rt[1].top,TEXT("确定"),4);//输出文本TextOut(hdc,rt[1].left+=50,rt[1].top,TEXT("清除"),4);//输出文本TextOut(hdc,40,350,TEXT("提示:双击窗口退出"),18);//输出文本SetConsoleCursorPosition(hOut, pos3_1);ShowWindow(hwnd,SW_SHOW);SetConsoleTextAttribute(hOut, 10);for(;;){SetConsoleTextAttribute(hOut, 10);ReadConsoleInput(hIn, &mouseRec, 1, &res);Sleep(100);if (mouseRec.EventType == MOUSE_EVENT){if (mouseRec.Event.MouseEvent.dwEventFlags == DOUBLE_CLICK) break;if (mouseRec.Event.MouseEvent.dwButtonState == FROM_LEFT_1ST_BUTTON_PRESSED){GetCursorPos(&pt);ScreenToClient(hwnd,&pt);if(pt.x>20&& pt.x<50 &&pt.y>rt[1].top && pt.y<rt[1].bottom){if(xyear<4) printf("1");xyear++;if(xyear==1) year=1*1000;if(xyear==2) year=year+1*100;if(xyear==3) year=year+1*10;if(xyear==4){year=year+1;printf("\n你选择的年为%d",year);}continue;}else if(pt.x>rt[2].left && pt.x<rt[2].right &&pt.y>rt[2].top && pt.y<rt[2].bottom){if(xyear<4) printf("2");xyear++;if(xyear==1) year=2*1000;if(xyear==2) year=year+2*100;if(xyear==3) year=year+2*10;if(xyear==4){year=year+2;printf("\n你选择的年为%d",year);}continue;}else if(pt.x>rt[3].left && pt.x<rt[3].right &&pt.y>rt[3].top && pt.y<rt[3].bottom){if(xyear<4) printf("3");xyear++;if(xyear==1) year=3*1000;if(xyear==2) year=year+3*100;if(xyear==3) year=year+3*10;if(xyear==4){year=year+3;printf("\n你选择的年为%d",year);}continue;}else if(pt.x>rt[4].left && pt.x<rt[4].right &&pt.y>rt[4].top && pt.y<rt[4].bottom){if(xyear<4) printf("4");xyear++;if(xyear==1) year=4*1000;if(xyear==2) year=year+4*100;if(xyear==3) year=year+4*10;if(xyear==4){year=year+4;printf("\n你选择的年为%d",year);}continue;}else if(pt.x>rt[5].left && pt.x<rt[5].right &&pt.y>rt[5].top && pt.y<rt[5].bottom){if(xyear<4) printf("5");xyear++;if(xyear==1) year=5*1000;if(xyear==2) year=year+5*100;if(xyear==3) year=year+5*10;if(xyear==4){year=year+5;printf("\n你选择的年为%d",year);}continue;}else if(pt.x>rt[6].left && pt.x<rt[6].right &&pt.y>rt[6].top && pt.y<rt[6].bottom){if(xyear<4)printf("6");xyear++;if(xyear==1) year=6*1000;if(xyear==2) year=year+6*100;if(xyear==3) year=year+6*10;if(xyear==4){year=year+6;printf("\n你选择的年为%d",year);}continue;}else if(pt.x>rt[7].left && pt.x<rt[7].right &&pt.y>rt[7].top && pt.y<rt[7].bottom){if(xyear<4)printf("7");xyear++;if(xyear==1) year=7*1000;if(xyear==2) year=year+7*100;if(xyear==3) year=year+7*10;if(xyear==4){year=year+7;printf("\n你选择的年为%d",year);}continue;}else if(pt.x>rt[8].left && pt.x<rt[8].right &&pt.y>rt[8].top && pt.y<rt[8].bottom){if(xyear<4)printf("8");xyear++;if(xyear==1) year=8*1000;if(xyear==2) year=year+8*100;if(xyear==3) year=year+8*10;if(xyear==4){year=year+8;printf("\n你选择的年为%d",year);}continue;}else if(pt.x>rt[9].left && pt.x<rt[9].right &&pt.y>rt[9].top && pt.y<rt[9].bottom){if(xyear<4)printf("9");xyear++;if(xyear==1) year=9*1000;if(xyear==2) year=year+9*100;if(xyear==3) year=year+9*10;if(xyear==4){year=year+9;printf("\n你选择的年为%d",year);}continue;}else if(pt.x>rt[10].left && pt.x<rt[10].right &&pt.y>rt[10].top && pt.y<rt[10].bottom){if(xyear<4) printf("0");xyear++;if(xyear==1) year=0*1000;if(xyear==2) year=year+0*100;if(xyear==3) year=year+0*10;if(xyear==4){year=year+0;printf("\n你选择的年为%d",year);}continue;}else if(pt.x>rt[11].left && pt.x<rt[11].right &&pt.y>rt[11].top && pt.y<rt[10].bottom){if(xyear>=1&&year!=0){clear();yearbak=year;SetConsoleCursorPosition(hOut, pos3_2);printf("公元%d年",yearbak);SetConsoleCursorPosition(hOut, pos3_1);for(i=1;i<=6;i+=3)huizs(i);x=MessageBox(NULL,"是否显示后六个月?", "提示",MB_YESNO);if(x==6) {SetConsoleTextAttribute(hOut, 14);clear();for(i=7;i<=12;i+=3)huizs(i);}}else printf("输入不合法,请点击清除重新输入");continue;}else if(pt.x>rt[12].left && pt.x<rt[12].right &&pt.y>rt[12].top && pt.y<rt[12].bottom){xyear=0;year=0;clear();clock_sz();hzdy(nowyear,nowmonth);pn=CreatePen(PS_SOLID,2,RGB(255,255,0));SelectObject(hdc, pn);//选画笔MoveToEx(hdc,5,75,NULL);LineTo(hdc,45,75);SetConsoleCursorPosition(hOut, pos);continue;}};}}ReleaseDC(hwnd,hdc);}int pd( int year){int pr=0;if((year%100==0)&&(year%400==0))pr=1;else if(year%4==0&&year%100!=0)pr=1;else pr=0;return pr;}void huizs(int line_head_month){int i=0,j=0,k=0,month=0,n=0,daysum=0,jlw=0;int monthhead[13]={0},mlt[3]={1,1,1};int endline=0,test=0;int year=0;year=yearbak;for(i=1;i<year;i++){if(pd(i))daysum+=366;else daysum+=365;}j=daysum%7;monthhead[0]=j;for(month=1;month<=12;month++){if(pd(year)&&month==2) n=29;else if(pd(year)==0&&month==2) n=28;else if(month==4||month==6||month==9||month==11) n=30;else n=31;monthhead[month]=(monthhead[month-1]+n)%7;}while(test<=5){for(month=line_head_month;month<=(line_head_month+2);month++){if(month%3==1&&endline==0){printf("\t%d月\t\t\t%d月%d月\n",month,month+1,month+2);printf("一二三四五六日一二三四五六日一二三四五六日\n");}if(endline==0){for(k=0;k<monthhead[month-1];k++)printf(" ");j=monthhead[month-1];}if(endline==0) i=1;else i=mlt[month-1];for(;j<7;i++,j++){if(pd(year)&&month==2) n=29;else if(pd(year)==0&&month==2) n=28;else if(month==4||month==6||month==9||month==11) n=30;else n=31;if(i>n){for(k=0;k<7-j;k++)printf(" ");break;}printf("%-3.0d",i);}printf(" ");mlt[month-1]=i;if(month%3==0){printf("\n");endline=1;}j=0;}test++;}}void hzdy(int year,int nowmonth_hz){int i=0,j=0,k=0,month=0,n=0,daysum=0,jlw=0;int monthhead[13]={0},mlt[3]={1,1,1};int endline=0,test=0;for(i=1;i<year;i++){if(pd(i))daysum+=366;else daysum+=365;}j=daysum%7;monthhead[0]=j;for(month=1;month<=12;month++){if(pd(year)&&month==2) n=29;else if(pd(year)==0&&month==2) n=28;//平年else if(month==4||month==6||month==9||month==11) n=30;else n=31;monthhead[month]=(monthhead[month-1]+n)%7;}if(pd(year)&&nowmonth_hz==2) n=29;//闰年else if(pd(year)==0&&nowmonth_hz==2) n=28;//平年else if(nowmonth_hz==4||nowmonth_hz==6||nowmonth_hz==9||nowmonth_hz==11) n=30;//4,6,9,11月else n=31;printf("\n\n\n\n\n\n\n\n 当前时间:%d年%d月%d日%d时%d分\n\n",nowyear,nowmonth,nowday,hour,min);printf("\t一二三四五六日\n\t");for(k=0;k<monthhead[nowmonth_hz-1];k++)printf(" ");j=monthhead[nowmonth_hz-1];for(i=1;i<=n;i++,j++){if(j==7){printf("\n\t");j=0;}printf("%-3.0d",i);}printf("\n");}void clock_sz(){float a,b,c;float x=0,y=0,ex=100,ey=160,radian=0,oldx,oldy,radius=90;float mx=0,my=0,oldmx,oldmy,mradius=40;float hx=0,hy=0,oldhx,oldhy,hradius=20;intkd_r1,kd_r2,kd_radius=170,kd_radius1,old_kd_x,old_kd_y,kd_radian=0,k=0,q=0,oldk,oldq;HWND hwnd;HANDLE hOut;HDC hdc;COLORREF C1=RGB(0,0,0),C2=RGB(0,0,0);HBRUSH hbr,hbr1,hbr2;HPEN hpn,gpn,rpn,ppn2,ypn,bpn,kdpn,rkdpn,dotpn,blue,black,blkdpn,pkdpn,hpn2;hwnd=GetConsoleWindow();hdc = GetDC(hwnd);hOut = GetStdHandle(STD_OUTPUT_HANDLE);hbr= CreateSolidBrush(RGB(0,100,0));hbr1= CreateSolidBrush(C1);hbr2= CreateSolidBrush(RGB(0,0,150));hpn2=CreatePen(PS_SOLID,1,RGB(255,0,0));rpn=CreatePen(PS_SOLID,1,RGB(255,0,0));ppn2=CreatePen(PS_SOLID,3,RGB(255,255,0)); hpn=CreatePen(PS_SOLID,1,RGB(0,255,255)); blue=CreatePen(PS_SOLID,3,RGB(0,0,255)); bpn=CreatePen(PS_SOLID,1,RGB(255,255,255)); gpn=CreatePen(PS_SOLID,2,RGB(0,255,0)); pkdpn=CreatePen(PS_SOLID,3,RGB(0,255,255)); kdpn=CreatePen(PS_SOLID,1,RGB(255,255,0)); rkdpn=CreatePen(PS_SOLID,4,RGB(255,0,0)); blkdpn=CreatePen(PS_SOLID,6,RGB(0,0,0)); black=CreatePen(PS_SOLID,4,C1);ex=400;//时钟圆心位置ey=230;while(kd_radian<=360){if(kd_radian%5==0){if(kd_radian%90==0){kd_radius=130;SelectObject(hdc,rkdpn);}else{kd_radius=125;SelectObject(hdc,pkdpn);}}else{kd_radius=130;SelectObject(hdc, kdpn);kd_radius1=120;}y=kd_radius*sin(kd_radian/180.0*3.14);x=kd_radius*cos(kd_radian/180.0*3.14);MoveToEx(hdc,ex,ey,NULL);LineTo(hdc,ex+x,ey+y);y=kd_radius1*sin(kd_radian/180.0*3.14);x=kd_radius1*cos(kd_radian/180.0*3.14);old_kd_x=x;old_kd_y=y;SelectObject(hdc,blkdpn);MoveToEx(hdc,ex,ey,NULL);LineTo(hdc,ex+old_kd_x,ey+old_kd_y);kd_radian+=6;};SetTextColor(hdc,RGB(0,255,0));SetBkColor(hdc,RGB(0,0,0));TextOut(hdc,ex+kd_radius+8,ey-7,TEXT("3"),1);TextOut(hdc,ex-4,ey+kd_radius+3,TEXT("6"),1);TextOut(hdc,ex-kd_radius-15,ey-5,TEXT("9"),1);TextOut(hdc,ex-7,ey-kd_radius-18,TEXT("12"),2);radius=110;mradius=90;//分针半径hradius=70;//时针半径x=0,y=0;radian=0;SetTextColor(hdc,RGB(0,255,225));////设颜色SetBkColor(hdc,RGB(0,0,0));////设颜色ti2();a=sec*6/180.0*3.14;b=min*6/180.0*3.14;c=(hour*30.0-90.0+(min+15)/2.0)/180.0*3.14;SetTextColor(hdc,RGB(0,255,255));my=mradius*sin(b);mx=mradius*cos(b);SelectObject(hdc, gpn);MoveToEx(hdc,ex,ey,NULL);LineTo(hdc,ex+mx,ey+my);LineTo(hdc,ex+mx,ey+my);hy=hradius*sin(c);hx=hradius*cos(c);SelectObject(hdc, blue);MoveToEx(hdc,ex,ey,NULL);LineTo(hdc,ex+hx,ey+hy);ReleaseDC(hwnd, hdc);}。
(完整版)C语言万年历
说明部分
在TC或VC6.0中编译程序,编译成功后,通过命令行向编译生成的可执行文件(.exe)传递参数,在命令行中输入该执行文件的路径名称,然后再输入传入的参数,回车,就会显示出运行结果,效果如图1.1所示。
图1.1万年历运行界面
代码部分
#include <stdio.h>
main(int a,char **date)
}
if (day<0||day>month)
{
printf ("\n ERROR! the entered DAY is invalid\n");
exit (0);
}
week=(dy+dm+day-1+6)%7;
if(week<0)
week+=7;
if (day>0) /***判定查看类型***/
{
if (d==-1) year=year*10+(date[1][i]-'0');
if (d==0) month=month*10+(date[1][i]-'0');
if (d==1) day=day*10+(date[1][i]-'0');
i++;
}
if (month<1||month>12)/*若月份传入错误数字*/
else
d=(year-2000)/4-(year-2000)/100+(year-2000)/400;
dy=(year-2000)+d; /***该年1月1号到2000年1月1号的"星期差" ***/
用c语言编写万年历
{
case 1:sum=0;break;
case 2:sum=31;break;
case 3:sum=59;break;
case 4:sum=90;break;
case 5:sum=120;break;
else goto loop2;
loop1: for(i=1901;i<year;i++)
{
if(i%400==0||(i%4==0&&i%100!=0))
n++;
}
days=(year-1901-n)*365+n*366;
case 11:sum=304;break;
case 12:sum=334;break;
default:printf("一年内只能有12个月!请重新输入!\n");goto redo;
case 3:printf("\t 五月 %d\t\t 六月 %d\n",year,year);break;
case 4:printf("\t 七月 %d\t\t 八月 %d\n",year,year);break;
goto redo;
}
if(month==6&&(day>=31||day<=0))
{
printf("输入有误!6月只能有30天!\n");
goto redo;
}
if(month==7&&(day>=32||day<=0))
{
printf("输入有误!7月只能有31天!\n");
万年历C语言代码
//ÍòÄêÀú#include <stdio.h>//±íÍ·void 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语言万年历代码
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 <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:");}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;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;int year,month,date;int day,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语言
#include"stdio.h"#include"stdlib.h"main( ){int Year,Month,Day; //年、月int FirstDay_Year,FirstDay_Month; //某年的第一天是星期几,某年某月的第一天是星期几(范围是0~6,其中0代表星期日)int IsLeapYear; //是否为闰年,0表示不是闰年,1表示是闰年int i,d,y,A,B,C,Y,M,D; //临时变量int riqi(int Year,int Month,int Day);//阳历转化为阴历的函数int yuefen(int Year,int Month,int Day);int nianfen(int Year,int Month,int Day);char YN; //Yes No,程序是否要继续int Days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};//Days[1~12]存储每个月有多少天,其中二月的天数是可变的(闰年29天,平年28天),这里初始化为28天printf(" 万年历\n"); //打印标题XunHuan: //循环标号(可以通过goto跳转到这里)printf("请输入年份: "); //提示输入年份(0~9999)scanf("%d",&Year); //把输入的年份赋值给变量Yearprintf("请输入月份: "); //提示输入月份(1~12)scanf("%d",&Month); //把输入的月份赋值给变量Monthprintf("请输入日期: "); //提示输入日期scanf("%d",&Day); //把输入的日期赋值给变量Dayy=Year;FirstDay_Year=5*(y/4)+(y%4)-(y/100)+(y/400);//蔡勒公式(计算某年的第一天是星期几) IsLeapYear=(((y%4==0&&y%100!=0)||y%400==0) && y!=0)?1:0;//判断是否为闰年Days[2]=(IsLeapYear==1)?29:28; //闰年二月29天,非闰年二月28天for(i=1,d=0;i<Month;i++)d=d+Days[i];FirstDay_Month=(d+FirstDay_Year)%7; //当月的第一天是星期几(0代表星期日)printf("\n**********************************************************\n");printf(" 公元%d 年%2d 月%2d日",Year,Month,Day); //打印年月A=nianfen(Year,Month,Day);B=yuefen(Year,Month,Day);C=riqi(Year,Month,Day);printf(" 农历%d 年%2d月%2d日",A,B,C);printf("\n**********************************************************\n");printf(" 星期日星期一星期二星期三星期四星期五星期六\n");//打印星期表头for(i=0;i<FirstDay_Month;i++)printf("%8c",' '); //当某月的第一天不是星期日时打印空格占位for(d=1;d<=Days[Month];d++) //循环,从每个月的第一天开始打印{if(d==Day){printf("%4c",' '); //显示被输入的日期if(Month==1&&Day==1){printf("\b\b元旦节");}else if(Month==2&&Day==14){printf("\b\b情人节");}else if(Month==3&&Day==8){printf("\b\b妇女节");}else if(Month==4&&Day==1){printf("\b\b愚人节");}else if(Month==4&&Day==5){printf("\b\b清明节");}else if(Month==5&&Day==1){printf("\b\b劳动节");}else if(Month==6&&Day==1){printf("\b\b儿童节");}else if(Month==8&&Day==1){printf("\b\b建军节");}else if(Month==10&&Day==1) {printf("\b\b国庆节");}else if(Month==10&&Day==5) {printf("\b\b教师节");}else{printf("[%2d]",d);}if(B==1&&C==1){printf("\b\b\b\b春节");}else if(B==1&&C==5){printf("\b\b\b\b\b\b元宵节"); }else if(B==5&&C==5){printf("\b\b\b\b\b\b端午节"); }else if(B==7&&C==7){printf("\b\b\b\b\b\b乞巧节"); }else if(B==8&&C==15){printf("\b\b\b\b\b\b中秋节"); }else if(B==9&&C==9){printf("\b\b\b\b\b\b重阳节"); }else if(B==12&&C==8){printf("\b\b\b\b\b\b腊八节"); }}else{printf("%6c",' ');printf("%2d",d);}if(((d+FirstDay_Month)%7)==0 && d<Days[Month])printf("\n"); //当输出了星期六而且还未输出所有天数时,换行}printf("\n**********************************************************\n"); printf("\n");printf("是否继续(Y/N)?\n");scanf("%c",&YN);scanf("%c",&YN);if(YN=='Y' || YN=='y')goto XunHuan;}int riqi(int Year,int Month,int Day){int q,r,t,i,a,s=0;int IsLeapYear;int Days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};IsLeapYear=(((Year%4==0&&Year%100!=0)||Year%400==0) && Year!=0)?1:0;Days[2]=(IsLeapYear==1)?29:28;q=(Year-1977)/4;r=(Year-1977)-4*q;for(i=0;i<Month;i++){s=s+Days[i];}t=(int)(14*q+10.6*(r+1)+s+Day)/29.5;a=(int)((14*q+10.6*(r+1)+s+Day)-t*29.5);while(Month==1){Year--;Month=Month+12;}Month=Month-1;return a;}int yuefen(int Year,int Month,int Day){int q,r,t,i,a,s=0;int Days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};q=(Year-1977)/4;r=(Year-1977)-4*q;for(i=1;i<Month;i++){s=s+Days[i];}t=(int)(14*q+10.6*(r+1)+s+Day)/29.5;a=(int)(14*q+10.6*(r+1)+s+Day)-t*29.5;while(Month==1){if(Day<23){Year=Year-1;Month=Month+12;}else{Month=Month+1;} }Month=Month-1;return Month;}int nianfen(int Year,int Month,int Day){int q,r,t,i,a,s=0;int Days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};q=(Year-1977)/4;r=(Year-1977)-4*q;for(i=1;i<Month;i++){s=s+Days[i];}t=(int)(14*q+10.6*(r+1)+s+Day)/29.5;a=(int)(14*q+10.6*(r+1)+s+Day)-t*29.5;while(Month==1&&Day<25){Year--;Month=Month+12;}Month=Month-1;return Year;}。
万年历 c语言程序代码
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语言实现万年历程序
week=(sum+1)%7; //表示该年1月1日为星期几
if(year(y)==366) days[1]=29;
printf("\n%d年日历如下:\n\n",y);
for(i=0;i<12;i++) { printf(" %d月 \n",i+1); printf(" 7 1 2 3 4 5 6\n"); printf("=====================\n"); begin=1; for(j=0;j<week;j++) printf(" "); while(begin<=days[i]) { printf("%3d",begin); begin++; week=(week+1)%7; if(week%7==0) printf("\n"); } printf("\n\n");
这篇文章主要介绍了visualstudio2000系列版本安装opengl的图文教程本文通过图文并茂的形式给大家介绍的非常详细对大家的学习或工作具有一定的参考借鉴价值需要的朋友可以参考下
C语 言 实 现 万 年 历 程 序
本文实例为大家分享了C语言实现万年历程序,供大家参考,具体内容如下
#include <stdio.h>
}
return 0; }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
万年历c程序
#include "reg52.h"#include "absacc.h"#define LED P0#define DIG P2#define key_io P1void display();void key_scan(void);void key_scan_proc(void);void display_one();unsigned char k = 0;unsigned char key_flag;unsigned char key_return;unsigned char t = 0;unsigned char disp_flag;unsigned char disp_num;unsigned char bell_flag;unsigned char set[6];unsigned char set_time[6];unsigned char disp[7];sbit CLK = P3^4; /*实时时钟时钟线引脚*/ sbit IO = P3^5; /*实时时钟数据线引脚*/ sbit RST = P3^6; /*实时时钟复位线引脚*/ sbit dq = P1^4; /*ds18b20*/sbit ACC0 = ACC^0;sbit ACC7 = ACC^7;//sbit key1 = P1^0;//sbit key2 = P1^1;//sbit key3 = P1^2;//sbit key4 = P1^3;sbit light = P3^0;sbit bell = P3^7;/**********************************************************延时子函数**********************************************************/ void delay(unsigned char dly){while(dly--);}/***********************************************************向DS1302写入1Byte数据***********************************************************/ void InputByte(unsigned char ucDa){unsigned char i;ACC = ucDa;for(i=8; i>0; i--){IO = ACC0;CLK = 1;CLK = 0;ACC >>= 1;}}/***********************************************************从DS1302读取1Byte数据***********************************************************/ unsigned char OutputByte(void){unsigned char i;for(i=8; i>0; i--){ACC >>= 1;ACC7 = IO;CLK = 1;CLK = 0;}return(ACC);}/***********************************************************向DS1302指定地址写数据***********************************************************/ void W_1302(unsigned char Addr, unsigned char Da){RST = 0;CLK = 0;RST = 1;InputByte(Addr); //写地址InputByte(Da); //写1Byte数据CLK = 1;RST =0;}/***********************************************************读取DS1302某地址的数据***********************************************************/ unsigned char R_1302(unsigned char Addr){unsigned char Da;CLK = 0;RST = 0;RST = 1;InputByte(Addr); // 地址,命令Da = OutputByte(); //读1Byte数据RST =0;CLK = 1;return(Da);}/*************************************************************初始化ds18b20*************************************************************/ void rst_18b20(void){dq=1;delay(8);dq=0;delay(80);dq=1;delay(35);}/*************************************************************读ds18b20一个byte数据*************************************************************/ unsigned char read_18b20(void){unsigned char i,dat=0;for(i=0;i<=7;i++){dq=0;dat>>=1;dq=1;if(dq==1)dat|=0x80;delay(4);}return(dat);}/*************************************************************向ds18b20写入一个byte 数据**************************************************************/ void write_18b20(unsigned char dat){unsigned char i;for(i=0;i<8;i++){dq=0;dq=dat&0x01;delay(5);dq=1;dat>>=1;}}/**************************************************************读取温度值ds18b20**************************************************************/ unsigned int read_T(void){unsigned int t=0; //16 bitunsigned char t0=0,t1=0;float temp=0; //32 bitrst_18b20();write_18b20(0xcc);write_18b20(0x44);rst_18b20();write_18b20(0xcc);write_18b20(0xbe);t0=read_18b20();t1=read_18b20();t=t1;t<<=8;t=t+t0;t>>=4;/*t = (t0>>1);temp=t*0.0625;t=temp*10+0.5;*/return(t);}void main(void){W_1302(0x8e,0x00);//开保护W_1302(0x8c,0x09);//yearW_1302(0x8a,0x05);//weekW_1302(0x88,0x05);//mouthW_1302(0x86,0x29);//dateW_1302(0x84,0x15);//hourW_1302(0x82,0x59);//minuteW_1302(0x80,0x00);//secondW_1302(0x8e,0x80);//写保护TMOD = 0x01;TH0 = 0xFa;TL0 = 0xFF;EA = 1;ET0 = 1;TR0 = 1;bell = 1;disp_flag = 0;disp_num = 0;key_flag = 0;bell_flag = 0;while(1){while(disp_flag==0){display();if(light==0){DIG = 0X00;disp_flag = 2;}}while(disp_flag==1)display_one();if(light==1)disp_flag = 0;}}/*********************************************************扫描显示函数*********************************************************/ void display(void){switch(k){case 0:LED = (disp[0]&0XF0)+(disp[4]>>4);DIG = 0X80;break;case 1:LED = (disp[0]<<4)+(disp[4]&0X0F);DIG = 0X40;break;case 2:LED = (disp[1]&0X10)+(disp[5]>>4);DIG = 0X20;break;case 3:LED = (disp[1]<<4)+(disp[5]&0X0F);DIG = 0X10;break;case 4:LED = (disp[2]&0X30)+(disp[6]>>4);DIG = 0X08;break;case 5:LED = (disp[2]<<4)+(disp[6]&0X0F);DIG = 0X04;delay(15);break;case 6:LED = 0xf0+t/10;DIG = 0X02;break;case 7:LED = (disp[3]<<4)+t%10;DIG = 0X01;//while(1);break;case 8:DIG = 0X00;if(key_flag==0){t = read_T();disp[0]=R_1302(0x8d); //yeardisp[1]=R_1302(0x89); //monthdisp[2]=R_1302(0x87); //datadisp[3]=R_1302(0x8b); //weekdisp[4]=R_1302(0x85); //hourdisp[5]=R_1302(0x83); //mintedisp[6]=R_1302(0x81); //secondif((disp[4]==set_time[0])&&(disp[5]==set_time[1])){bell = 0;}else bell = 1;}key_scan();break;}}void display_one(){key_scan();switch(disp_num){case 1:{DIG = 0x00;LED = (disp[0]&0XF0)+0x0f;DIG = 0X80;delay(100);DIG = 0x00;LED = (disp[0]<<4)+0x0F;DIG = 0X40;delay(100);break;}case 2:{DIG = 0x00;LED = (disp[1]&0X10)+0x0f;DIG = 0X20;delay(100);DIG = 0x00;LED = (disp[1]<<4)+0x0F;DIG = 0X10;delay(100);break;}case 3:{DIG = 0x00;LED = (disp[2]&0Xf0)+0x0f;DIG = 0X08;delay(100);DIG = 0x00;LED = (disp[2]<<4)+0x0F;DIG = 0X04;delay(100);break;}case 4:{DIG = 0x00;LED = 0xff;DIG = 0X00;delay(100);DIG = 0x00;LED = (disp[3]<<4)+0x0F;DIG = 0X01;delay(100);break;}case 5:{DIG = 0x00;LED = (disp[4]>>4)+0xF0;DIG = 0X80;delay(100);DIG = 0x00;LED = (disp[4]&0x0F)+0xF0;DIG = 0X40;delay(100);break;}case 6:{DIG = 0x00;LED = (disp[5]>>4)+0xF0;DIG = 0X20;delay(100);DIG = 0x00;LED = (disp[5]&0x0F)+0xF0;DIG = 0X10;delay(100);break;}}}/***********************************************************按键识别程序***********************************************************/ void key_scan(void){unsigned char key_data = 0;key_io = 0xff;key_data = key_io&0x0f;if(key_data == 0xff)key_flag = 0;else{delay(30);key_io = 0xff;if(((key_io&0x0f) != 0x0f)&&((key_io&0x0f) == key_data)){while(key_io != 0xff);switch (key_data){case 0x0e : {key_return = 0;key_flag = 1;break;}case 0x0d : {key_return = 1;key_flag = 1;break;}case 0x0b : {key_return = 2;key_flag = 1;break;}case 0x07 : {key_return = 3;key_flag = 1;break;}default : break;}}if(key_flag==1){disp_flag = 1;key_flag = 0;key_scan_proc();}}}/***************************************************************按键函数***************************************************************/ void key_scan_proc(void){ int set;switch (key_return){case 0:{disp_num+=1;if(disp_num==7){W_1302(0x8e,0x00);//开保护W_1302(0x8c,disp[0]);//yearW_1302(0x8a,disp[3]);//weekW_1302(0x88,disp[1]);//mouthW_1302(0x86,disp[2]);//dateW_1302(0x84,disp[4]);//hourW_1302(0x82,disp[5]);//minuteW_1302(0x80,0x00);//secondW_1302(0x8e,0x80);//写保护disp_flag = 0;disp_num = 0;}break;case 1:{set = (disp[disp_num-1]>>4)*10+(disp[disp_num-1]&0x0f)-1;if(disp_num==1&&set==-1)set=99;else if(disp_num==2&&set==0)set=12;else if(disp_num==3&&set==0){if(disp[1]==2)set = 29;elseif(disp[1]==1||disp[1]==3||disp[1]==5||disp[1]==7||disp[1]==8||disp[1]==0x10||disp[1] ==12)set = 31;else if(disp[1]==4||disp[1]==6||disp[1]==9||disp[1]==0x11)set = 30;}else if(disp_num==4&&set==0)set=7;else if(disp_num==5&&set==-1)set=23;else if(disp_num==6&&set==-1)set=59;disp[disp_num-1]=((set/10)<<4)+(set%10);break;}case 2:set = ((disp[disp_num-1]>>4)*10+(disp[disp_num-1]&0x0f))+1;if(disp_num==1&&set==100)set=0;else if(disp_num==2&&set==13)set=1;else if(disp_num==3){if(set==30&&disp[1]==2)set = 1;elseif(set==32&&(disp[1]==1||disp[1]==3||disp[1]==5||disp[1]==7||disp[1]==8||disp[1]== 0x10||disp[1]==12))set = 1;elseif(set==31&&(disp[1]==4||disp[1]==6||disp[1]==9||disp[1]==0x11))set = 1;}else if(disp_num==4&&set==8)set=1;else if(disp_num==5&&set==24)set=0;else if(disp_num==6&&set==60)set=0;disp[disp_num-1]=((set/10)<<4)+(set%10);break;}case 3:{disp_flag = 1;bell_flag = 1;switch(disp_num){case 0: { disp_num = 5;break;}case 5:{ disp_num = 6;break;}case 6: {set_time[0] = disp[4];set_time[1] = disp[5];disp_flag = 0;bell_flag = 0;disp_num = 0;break;}}break;}default :break;}}/*************************************************************定时器中断函数*************************************************************/ void timer0() interrupt 1{TH0 = 0xFC; TL0 = 0xFF; k++;if(k==20){k =0;}}。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
fflush(stdin);
scanf("%c",&i);
if(i=='N'||i=='n')
break;
}
break;
case 5:
break;
default:
printf("\n对不起输入错误!\n");
}
}
}
int leap(int y)
{
if((y%4==0&&y%100!=0)||(y%400==0))
return 1;
பைடு நூலகம் else return 0;
printf("%3d",j++);
if(k==7)
{
printf("\n");
printf("%3d",j++);
}
for(;j<=monthday(y,m);j++)
{
printf("%10d",j);
if((j+k-1)%7==0&&j<monthday(y,m))
printf("\n\n");
printonemonth(2011,6);
printf("\n");
while(1)
{
printf("\n请输入您的操作:\n");
printf("\n1 查询该年是不是闰年");
printf("\n2 打印某一年的日历");
scanf("%d",&year);
is_leapyear(year);
printf("\n您是否继续?(Y/N)\n");
fflush(stdin);
scanf("%c",&i);
if(i=='N'||i=='n')
fflush(stdin);
printf("Are you sure?(Y/N)");
scanf("%c",&i);
if(i=='Y'||i=='y')
exit(0);
break;
}
break;
case 2:
while(1)
{ printf("您想要打印哪一年的日历:\n");
scanf("%d",&year);
printallyear(year);
printf("\n");
printf("\n您是否继续?(Y/N)\n");
}
void is_leapyear(int y)
{
if(leap(y))
printf("\n%d 是闰年\n",y);
else printf("\n%d 不是闰年\n",y);
}
int monthday(int y,int m)
{
int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
fflush(stdin);
scanf("%c",&i);
if(i=='N'||i=='n')
break;
}
break;
case 3:
while(1)
{ printf("您想要打印哪年哪月的日历:\n");
scanf("%d %d",&year,&month);
printonemonth(year,month);
printf("\n\n\n");
if(month==12)
printonemonth(year+1,1);
else
printonemonth(year,month+1);
printf("\n");
printf("\n您是否继续(Y/N)\n");
fflush(stdin);
scanf("%c",&i);
if(i=='N'||i=='n')
break;
}
break;
case 4:
while(1)
{
printf("请输入您要查询的年,月,日:\n");
scanf("%d %d %d",&year,&month,&day);
searchsomeday(year,month,day);
{
printonemonth(y,m);
printf("\n\n");
}
}
void searchsomeday(int y,int m,int d)
{
int i;
i=search1(y,m,d);
char xq[][10]={"星期一","星期二","星期三","星期四","星期五","星期六","星期日"};
void printonemonth(int y,int m);
void printallyear(int y);
void searchsomeday(int y,int m,int d);
void main()
{
int info,year,month,day;
char i;
printonemonth(2011,5);
printf("\n今天是 %s\n",xq[i-1]);
}
printf("\n3 打印某一月的日历并自动翻页");
printf("\n4 查询某一天是星期几");
printf("\n5 退出\n");
scanf("%d",&info);
switch(info)
{
case 1:
while(1)
{ printf("请输入您想要查询的年份:\n");
#include"stdio.h"
#include"conio.h"
#include"stdlib.h"
int leap(int y);
void is_leapyear(int y);
int monthday(int y,int m);
int search1(int y,int m,int d);
return A;
}
void printonemonth(int y,int m)
{
int i,j=1,k;
k=search1(y,m,1);
char yue[][12]={"01","02","03","04","05","06",
"07","08","09","10","11","12"};
if(leap(y))
a[2]=29;
return a[m];
}
int search1(int y,int m,int d)
{
int A;
if((m==1)||(m==2))
{
m+=12;
y--;
}
A=(d+2*m+(3*(m+1)/5)+y+(y/4)-(y/100)+(y/400))%7+1;
printf(" %d / %s\n\n",y,yue[m-1]);
printf("星期一 星期二 星期三 星期四 星期五 星期六 星期日\n");
for(i=1;i<k;i++)
printf(" ");
{
printf("\n");
j++;
printf("%3d",j);
}
else if((j+k-1)%7==0&&j==monthday(y,m))
printf("\n");
}
}
void printallyear(int y)
{
int m;
for(m=1;m<=12;m++)