C语言万年历编写

合集下载

C 万年历及公历农历转换源代码1

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语言万年历代码

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语言万年历程序

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语言:万年历

c语言:万年历
}
else if(m==4||m==6||m==9||m==11)/*在一定程度上避免输入的天数出错*/
{ if(d>0&&d<=30);
else {printf("错误!");goto begin;}
}
else if(m==2&&x==1)
{ if(d>0&&d<=29);
if(rey==0) while(getchar()!='\n');
if(y>0);
else {printf("错误!");goto begin;}/*在一定程度上避免输入的年份出错*/
x=Year(y);
if(x==1) printf("闰年\n");
if(x==0) printf("平年\n");
if(s==5) printf("星期五\n");
if(s==6) printf("星期六\n");
}
else printf("错误!");/*防止输入菜单错误*/
goto begin;
esc:printf("Thinks\n");
}
int Year(int n) /* 函数名:Year */
{
printf(" %d ",k);
if((j+k)%7==0) printf("\n");
}
}
else if(a==4)/*打印某年日历*/
{
printf("Input yeas:\n");

C语言实训--万年历源代码

C语言实训--万年历源代码

C语言实训--万年历源代码# include#include#include#include#include# define YEAR 365int numday[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31}, {31,29,31,30,31,30,31,31,30,31,30,31}};int leap(int year);int calday(int y,int m);int counterdays(int year,int month,int day);int week(int year,int month,int day);int eachyeartotal(int year,int month,int day);int maxDay(int y,int month);void print(int y,int m,int w);void festival (int year,int month,int day);int IsLeap(int y);int guanli(int i);void rili(int year,int month);int rili1();void rili2();void rili3();void rili4();void rili5();void fan();void show(int year,int month,int date,int sec,int mini,int hour);int main(){int i;printf("***************************************\n"); printf("1.查询日历,输入年份:\n");printf("2.查询该月日历及对应星期,输入年份和月份:\n"); printf("3.查询星期几及节日,输入年月日:\n");printf("4.距您输入日期还有多少天,输入日期:\n"); printf("5.通过键盘上下控制不同年月日:\n");scanf("%d",&i);guanli(i);return 0;}int guanli(int i){switch(i){case 1:rili1();return main();case 2:rili2();return main();case 3:rili3();return main();case 4:rili4();return main();case 5:rili5();return main();}return 0;}int rili1(){int year;int n,i;printf("输入年份:");scanf("%d",&year);printf("the calendar of the year%d\n",year);printf("\n");printf("=============================\n"); for(i=1;i<13;i++){printf(" %d月份\n",i);rili(year,i);}n = leap(year);return 0;}void rili2(){int year,month,w;printf("输入年月:");scanf("%d%d",&year,&month);w=calday(year,month);print(year,month,w);}void rili3(){int year,month,day,number;printf("输入年月日:");scanf("%d%d%d",&year,&month,&day);festival(year,month,day);number= week(year,month,day);printf("星期%d",number);}void rili4(){int year,month,day;printf("输入年月日:");scanf("%d%d%d",&year,&month,&day); eachyeartotal( year,month,day);counterdays(year,month,day);}void rili5(){int year,month,date,sec,mini,hour;fan();show(year,month,date,sec,mini,hour);}int leap(int year){int n=(year%4==0 && year%100!=0 || year%100!=0); return n;}void rili(int year,int month){int i,day,first_day,flag,year1,year2;int temp = 6;flag =leap(year);year1=year/100;year2=year%100;if(year>2000){year1=year1-20;day = year1/4;day+=(YEAR+24)*year1+YEAR*year2+(year2-1)/4;if(year>2000)day++;switch(month){case 1:day; break;case 2:day+=31;break;case 3:day+=59+flag;break;case 4:day+=90+flag;break;case 5:day+=120+flag;break;case 6:day+=151+flag;break;case 7:day+=181+flag;break;case 8:day+=212+flag;break;case 9:day+=243+flag;break;case 10:day+=273+flag;break;case 11:day+=304+flag;break;case 12:day+=334+flag;break;}day+=temp;first_day=day%7;}else{year1 = 20-1-year;year2=100-year2-1;day+=(YEAR+24)*year1+YEAR*year2+year2/4; switch(month){case 12:day+=31;break;case 11:day+=61;break;case 10:day+=92;break;case 9:day+=122;break;case 8:day+=153;break;case 7:day+=184;break; case 6:day+=214;break; case 5:day+=245;break; case 4:day+=275;break; case 3:day+=306;break; case 2:day+=334+flag;break; case 1:day+=365+flag;break; }day-=temp;day = day%7;first_day=(7-day)%7;}switch(month){case 1:case 2:month=28+flag;break; case 3:case 4:case 5:case 6:case 7:case 8:case 9:case 10:case 11:month=30;break; case 12:month =31;break;}for(i=1;i<4*first_day;i++) printf(" ");for(i=0;i<month;i++)< p="">{printf("%4d",i+1);if((first_day+i)%7==6)printf("\n");}printf("\n");printf("===============================\n");}///////////////////////////////////////////////////////////int counterdays(int year,int month,int day){int year1,days0,days1,month1,days,day1;time_t timep;struct tm*p;time(&timep);p=gmtime(&timep);year1=(1900+p->tm_year);month1=(1+p->tm_mon);day1=(p->tm_mday);days0=(year-1)*365 + (year-1)/4 - (year-1)/100 + (year-1)/400 +eachyeartotal (year,month,day);days1=(year1 - 1)*365+(year1-1)/4-(year1-1)/100 + (year1 - 1)/400 +eachyeartotal (year1,month1,day1);days=days0-days1;printf("\n今天距%d年%d月%d日还有%d天\n\n",year,month,day,days);return days;}int eachyeartotal(int year,int month,int day){int i,sum=0;for(i=1;i<month;i++)< p="">{sum+=maxDay(year,i);}sum+=day;return sum;}int IsLeap(int y){if(y%4==0 && y%100!=0 || y%400==0) return 1; else return 0;}int maxDay(int y,int month){int a[12]={31,28,31,30,31,30,31,31,30,31,30,31};if(IsLeap(y))a[1]=29;return a[month-1];}///////////////////////////////////////void festival (int year,int month,int day){if (month==1 && day==1) printf (",这天是元旦");if (month==2 && day==14) printf (",这天是情人节"); if (month == 3)switch(day){case 8:printf (",这天是妇女节"); break;case 12:printf (",这天是植树节");}if (month==1 && day==1) printf (",这天是愚人节");if(month == 5)switch (day){case 1:printf(",这天是劳动节");break;case 4:printf(",这天是青年节");}if (month==6 && day==1) printf (",这天是儿童节");if (month==7 && day==1) printf (",这天是建党节");if (month==8 && day==1) printf (",这天是建军节");if (month==9 && day==10) printf (",这天是教师节");if (month==10 && day==1) printf (",这天是国庆节");printf("\n");}int week(int year,int month,int day){int number = (year-1)+(year-1)/4 - (year-1)/100+(year-1)/400+eachyeartotal(year,month,day);number = number%7;return number;}/////////////////////////////////////////////void print(int y,int m,int w){int i,l;printf("Calendar %d-%02d\n",y,m);printf("---------------------\n");printf("Su Mo Tu We Th Fr Sa \n");printf("---------------------\n");for (i=0;i<w;i++)< p=""> printf(" ");if (IsLeap(y))l=1;elsel=0;for (i=1;i<=numday[l][m-1];i++) {printf("%-3d",i);w++;if (w%7==0)printf("\n");}if (w%7) printf("\n");printf("---------------------\n"); }int calday(int y,int m){int d=0,w;while (y>1910){if (IsLeap(y)) d+=366;else d+=365;y--;}while (m>1){ --m;d+=numday[0][m-1];}w=(d+1)%7;return w;}//////////////////////////////////////////void show(int year,int month,int date,int sec,int mini,int hour) {const char month_str[][4]={"","Jan","Feb","Mar","Apl", "May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};const int month_day[]={0,31,28,31,30,31,30,31,31,30,31,30,31};int i,j,wdays,mdays,days;for(i=1,days=0;i<year;i++)< p="">{if(leap(i))days += 366;}else{days += 365;}}for(i=1;i<month;i++)< p="">{if(i==2 && leap(year)){days+=29;}else{days+=month_day[i];}}printf(" %s.%d.%d %d:%d:%d \n",month_str[month],date,year,hour,mini,sec);printf(" 一二三四五六日\n");wdays = days % 7;for( j = 0; j < wdays; j++){printf(" ");}if(month == 2 && leap(year)){mdays=29;}else{mdays= month_day[month];}for(i=1;i<=mdays;i++){if( i > 1 && days % 7 == 0 ){printf("\n");}printf("%4d",i);days=days+1; }printf("\n---------------------------\n\n\n");}{time_t rawtime;struct tm *info;int year,month,date,sec,mini,hour; char ch;time ( &rawtime );info = localtime ( &rawtime );year =info->tm_year + 1900; month =info->tm_mon + 1;date =info->tm_mday;hour =info->tm_hour;mini =info->tm_min;sec =info->tm_sec;while(1){show(year,month,date,sec,mini,hour); printf("↑......上一年\n\n");printf("↓......下一年\n\n");printf("←....前一个月\n\n");pr intf("→....后一个月\n\n");printf("Esc.......退出\n\n");ch=getch();switch(ch){case 27://Ecs exit(0);case -32://Navigatorch=getch();if(ch==77){//Rightyear+=(month==12)?1:0;month=month%12+1;}else if(ch==75){year-=(month==1)?1:0; month=(month-2+12)%12+1; }else if(ch==72)year--;else if(ch==80)year++;system("cls");}}</month;i++)<></year;i++)<></w;i++)<></month;i++)<></month;i++)<>。

c语言万年历

c语言万年历

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");} } }} } }。

1万年历(c语言,多功能)

1万年历(c语言,多功能)

#include "time.h" /*包含的头文件*/#include "stdio.h"#include "math.h"#include "windows.h"#include "conio.h"#define KEYNUMUp 0x48 /*宏定义*/#define KEYNUMDown 0x50#define KEYNUMLeft 0x4b#define KEYNUMRight 0x4dint eachyeartotal(int year,int month,int day>。

/*函数声明*/ int counterdays(int year,int month,int day>。

int nowtime(int year,int month,int day>。

int week(int year,int month,int day>。

int maxDay(int year,int month>。

int isleap(int year>。

void whatweek(int year,int month,int day>。

void display(int year ,int month>。

void display2(int year,int month>。

void display3(int year,int month,int day> 。

void setDay1(int year,int month,int day>。

void setDay2(int year,int month,int day>。

void setDay3(int year,int month,int day>。

void jieri(int month,int day>。

万年历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:");}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语言程序 万年历编程
{if (a%100==0)
{if (a%400==0)
ya=1;
}
else ya=1;
}
else ya=0;
}
if (ya==1||b==2)
c=28;
else c=29;
switch (b)
{
case 1:case 3:case 5:case 7:case 8:case 12:c=31;break;
case 2:x=29;break;
case 4: case 6: case 9: case 10: case 11:x=30;break;
}
wa=week(y,a,1);
if (wa=="星期日") j=0;
else if (wa=="星期一") j=1;
else if (wa=="星期二") j=2;
#include<math.h>
#include<stdio.h>
//求某个日期对应的星期
char w[][7]={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
int i,j,m,d,y;
char week(int a,int b,int c) //定义星期函数
else if (wa=="星期三") j=3;
else if (wa=="星期四") j=4;
else if (wa=="星期五") j=5;

(完整版)C语言万年历

(完整版)C语言万年历
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语言编写万年历

用c语言编写万年历
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;
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语言万年历代码

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 <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语言

新建 万年历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语言程序代码

万年历 c语言程序代码
{int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
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语言

万年历代码c语言

万年历代码c语言万年历是一种实用的日历工具,它可以根据年、月、日来显示当天的日期信息,并可以切换到其他日期来查询对应的日期信息。

在编写万年历的代码时,我们需要考虑输入的年份是否为闰年、每个月的天数、以及每个月第一天是星期几等等。

以下是一份使用C语言编写万年历的参考代码:```c#include <stdio.h>// 判断是否为闰年int isLeapYear(int year) {return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0); }// 获取某年某月的天数int getMonthDays(int year, int month) {int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};if (month == 2 && isLeapYear(year)) {return 29;}return days[month - 1];}// 获取某年某月第一天是星期几int getFirstDayOfWeek(int year, int month) {int day = 1;for (int i = 1800; i < year; i++) {if (isLeapYear(i)) {day = (day + 366) % 7;} else {day = (day + 365) % 7;}}for (int i = 1; i < month; i++) {day = (day + getMonthDays(year, i)) % 7;}return day;}int main() {int year, month;printf("请输入年份:");scanf("%d", &year);printf("请输入月份:");scanf("%d", &month);// 判断输入是否合法if (year < 1800 || month < 1 || month > 12) {printf("输入的年份或月份不合法!\n");return 0;}// 获取某年某月的天数和第一天是星期几int days = getMonthDays(year, month);int firstDayOfWeek = getFirstDayOfWeek(year, month); // 打印万年历printf("日一二三四五六\n");for (int i = 0; i < firstDayOfWeek; i++) {printf(" ");}for (int i = 1; i <= days; i++) {printf("%2d ", i);if ((firstDayOfWeek + i) % 7 == 0) {printf("\n");}}printf("\n");return 0;}```以上代码实现了一个简单的万年历功能,在控制台输出给定年份和月份的月历。

万年历C语言代码

万年历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>#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();}。

万年历c语言

万年历c语言

#include<stdio.h>#include<conio.h> /*颜色*/ ——————————————————————————————————main()/*主函数*/{int i;while(1) (使用循环使得函数程序运行可选择操作化!){void _search(void); /*调用的函数:即是自定义的查找函数*/printf("\t\t\twelcome!!\nchose your need:\nchose 1:Enter\t\t2:Exit\nChoice\t\t:"); switch(getch()) /*多分支选择函数*/ {case '1':system("cls");_search();break;case '2': break;;}printf("\nDo you want to go on?\n\t\t1(yes)\t2(not)\n");scanf("%d",&i);if(i==1) continue;elsebreak;}}——————————————————————————————————void _search(void) /*自定义的函数—打印出日历*/{int y,m,d,w,i; /*年,月,日,周*/int mdays[12]={31,28,31,30,31,30,31,31,30,31,30,31}; /*12个月的每个月天数*/ loop: /*循环*/printf("Input year,month,day:"); /*输入所需日期*/scanf("%d,%d,%d",&y,&m,&d);if((y>0)&&(m>=1&&m<=12)&&(d>=1&&d<=mdays[m-1])) /*+选择:满足1~12月且满足相应月的天数*/{system("cls"); /*清屏*/if(m== 1||m== 2) m+=12,y--;w=(y/1+y/4-y/100+y/400+2*m+3*(m+1)/5+1)%7+1;/*主要公式只取计算结果的整数部分。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
相关文档
最新文档