用C语言编写万年历,详细代码

合集下载

C语言编写的万年历代码

C语言编写的万年历代码

该代码在VC++6.0编译器下运行,只要按照编译器给出的说明操作,就能将万年历显示在调试窗口中了……………………………………由于制作时间匆忙,很多注释都来不及写了,对于出学者可以慢慢看,代码很简单的,都放在了主函数里,如果有兴趣的话,可以把这些代码放在几个文件里,这样会好看点,加油了!#include<stdio.h>#include<math.h>void main(){int m,i,j,n=0,y=2010,wo,w,a;printf("input the form of: year-month:\t");scanf("%d-%d",&y,&m); //输入格式的决定if(y%4==0&&y%100!=0||y%400==0)a=29;else a=28; //闰年的判断及2月日数的确定if(m<1||m>12){printf("month is not exit,please input later!\n");exit(0);}wo=(y+(y-1)/4-(y-1)/100+(y-1)/400)%7; //1月1日的算法wo表示for(i=0;i<55;i++)printf("*"); //*的输入printf("\n");for(j=1;j<=7;j++)printf("星期%d\t",j); //星期的输入printf("\n"); //表前的建造switch(m){case 1:for(i=1;i<wo;i++){printf("\t");n++;}for(j=1;j<=31;j++){if(n%7==0)printf("\n");printf("%d\t",j);n++;}break; // 1 month case 2:w=(wo+31)%7;for(i=1;i<w;i++){printf("\t");n++;}for(j=1;j<=a;j++){if(n%7==0)printf("\n");printf("%d\t",j);n++;}break; // 2 month case 3:w=(wo+31+a)%7;for(i=1;i<w;i++){printf("\t");n++;}for(j=1;j<=31;j++){if(n%7==0)printf("\n");printf("%d\t",j);n++;}break; // 3 month case 4:w=(wo+31+a+31)%7;for(i=1;i<w;i++){printf("\t");n++;}for(j=1;j<=30;j++){if(n%7==0)printf("\n");printf("%d\t",j);n++;}break; // 4 monthcase 5:w=(wo+31+a+31+30)%7;for(i=1;i<w;i++){printf("\t");n++;}for(j=1;j<=31;j++){if(n%7==0)printf("\n");printf("%d\t",j);n++;}break; // 5 monthcase 6:w=(wo+31+a+31+30+31)%7;for(i=1;i<w;i++){printf("\t");n++;}for(j=1;j<=30;j++){if(n%7==0)printf("\n");printf("%d\t",j);n++;}break; // 6 monthcase 7:w=(wo+31+a+31+30+31+30)%7;for(i=1;i<w;i++){printf("\t");n++;}for(j=1;j<=31;j++){if(n%7==0)printf("\n");printf("%d\t",j);n++;}break; // 7 monthcase 8:w=(wo+31+a+31+30+31+30+31)%7;for(i=1;i<w;i++){printf("\t");n++;}for(j=1;j<=31;j++){printf("\n");printf("%d\t",j);n++;}break; // 8 monthcase 9:w=(wo+31+a+31+30+31+30+31+31)%7;for(i=1;i<w;i++){printf("\t");n++;}for(j=1;j<=30;j++){if(n%7==0)printf("\n");printf("%d\t",j);n++;}break; // 9 monthcase 10:w=(wo+31+a+31+30+31+30+31+31+30)%7;for(i=1;i<w;i++){printf("\t");n++;}for(j=1;j<=31;j++){if(n%7==0)printf("\n");printf("%d\t",j);n++;}break; // 10 monthcase 11:w=(wo+31+a+31+30+31+30+31+31+30+31)%7;for(i=1;i<w;i++){printf("\t");n++;}for(j=1;j<=30;j++){if(n%7==0)printf("\n");printf("%d\t",j);n++;}break; // 11 monthcase 12:w=(wo+31+a+31+30+31+30+31+31+30+31+30)%7;for(i=1;i<w;i++){n++;}for(j=1;j<=31;j++){if(n%7==0)printf("\n");printf("%d\t",j);n++;}break; // 12 month}printf("\n");for(i=0;i<55;i++)printf("*");printf("\n"); //表尾的处理}。

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

屌神NO.1#include <stdio.h>#include <stdlib.h>#include <stdlib.h>#include <conio.h> /清屏函数的头文件*/#define X " Sun Mon Tue Wed Thu Fri Sat"void menu();int getday(int year,int month,int date);int isleap(int year);void print(int n);int day(int year);void printcalendar(int year);void menu(){system("cls"); /*清除屏幕上所有文字*/printf("\nTHIS IS THE MENU OF THE PROGRAM !");printf("\nYOU CAN CHOOSE THE NUMBER FOR THE FUNCTIOM:");printf("\n\n");printf("1 Find the day by year-month-date.\n");printf("2 Find out whether the year you input is a leap year.\n");printf("3 Print the calendar of the year you input.\n");printf("4 Exit.\n\n");printf("Input your choice:");}/*函数定义,将在主函数中调用*/int getday(int year,int month,int date){int isleap(int year);int flag,s,i;int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};int cont=0;flag=isleap(year);if(flag==1){a[2]++; /*修改二月份天数*/}for(i=1;i<month;i++){cont=cont+a[i];}cont=cont+date;s=year+1+(year-1)/4+(year-1)/100+(year-1)/400+cont;return s%7;}/*利用公式求星期几*/int isleap(int year){if(year%4==0&&year%100||year%400==0){return 1;}else{return 0;}}/*判定闰年*/void print(int n){int i;for(i=0;i<n;i++) printf(" ");}/*打印空格,排版使用*/int day(int year){long a,b;if(year<=2000){a=2000-year;b=6-(a+a/4-a/100+a/400)%7;return b;}else{a=year-2000;b=(a+1+(a-1)/4-(a-1)/100+(a-1)/400)%7+6;return b%7;}}/*打印日历函数*/void printcalendar(int year){int i,j,k,m,n,f1,f2,d;int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};printf("\nThe calendar of the year %d.\n\n",year);d=day(year);if(isleap(year)==1){a[2]++;}for(i=1;i<=12;i+=2){m=0; n=0; f1=0; f2=0;switch(i){case 1:printf(" Januray 1 ");break;case 3:printf(" March 3 ");break;case 5:printf(" May 5 ");break;case 7:printf(" July 7 "); break;case 9:printf(" September 9 ");break;case 11:printf(" Nevember 11 ");break;}print(21); /*打印空格,隔开奇偶月份名*/switch(i+1){case 2:printf(" February 2 "); break;case 4:printf(" April 4 "); break;case 6:printf(" June 6 "); break;case 8:printf(" August 8 "); break;case 10:printf(" October 10 "); break;case 12:printf(" December 12"); break;}printf("\n");printf(X); /*宏调用,打印星期字符串*/print(6); /*打印空格,隔开奇偶月份数据*/printf(X);printf("\n");for(j=0;j<6;j++){if(j==0){print(d*4); /*每个日期数采用个空格的宽度,即4字节。

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

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

c语言——万年历程序

c语言——万年历程序

#include<stdio.h>#include<stdlib.h>char*month_str[]={"January","February","March","April","May","June","July","August ","September","October","November","December"};char*week[]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Sat urday"};int IsLeapYear(int year) /*find out the year is leap year or not*/{if((year%4==0&&year%100!=0)||(year%400==0)) //这里是判断是否是闰年的return 1; //如果是闰年就返回值1elsereturn 0;//不是的话返回0}int month_day(int year,int month) //这个函数用来判断这年的月分有多少天的{int mon_day[]={31,28,31,30,31,30,31,31,30,31,30,31};if(IsLeapYear(year)&&month==2) /*判断是判断是否是闰年,如果是闰年而且这个月是2月那这个月有29天*/return 29;elsereturn(mon_day[month-1]);}int DaySearch(int year,int month,int day) /*这个函数是计算输入的日期对应的星期*/{int c=0;float s;int m;for(m=1;m<month;m++)c=c+month_day(year,m); //这是计算输入的月分的累计天数c=c+day; //计算日期在这一年中是第几天s=year-1+(int)(year-1)/4+(int )(year-1)/100+(int)(year-1)/400-40+c; /*这是计算日期对应的星期公式,这个公式可在网上查到*/return ((int)s%7); //与上语句同属计算日期对应的星期}int PrintAllYear(int year)/*这个函数是用来输出全年的日历*/{int temp;int i,j;printf("\n\n%d Calander\n",year);for(i=1;i<=12;i++){printf("\n\n%s(%d)\n",month_str[i-1],i); //输出月分名称printf("0 1 2 3 4 5 6 \n");printf("S M T W T F S \n\n");temp=DaySearch(year,i,1);for(j=1;j<=month_day(year,i)+temp;j++){if(j-temp<=0)printf(" ");else if(j-temp<10)printf("%d ",j-temp);elseprintf("%d ",j-temp);if(j%7==0)printf("\n");}}return 0;}int main(){int option,da;char ch;int year,month,day;printf("Copyright @ 2005 TianQian All rights reserved!:):):)");printf("\n\nWelcome to use the WanNianLi system!\n");while(1){printf("\nPlease select the service you need:\n"); //用来提示选择执行功能printf("\n1 Search what day the day is"); //选择1时,用来计算这一天是星期几printf("\n2 Search whether the year is leap year or not"); //计算是否这年是闰年printf("\n3 Print the calander of the whole year"); //输入全年的日历printf("\n4 Exit\n"); //选择退出程序scanf("%d",&option);switch(option) //用来选择执行{case 1:while(1){printf("\nPlease input the year,month and day(XXXX,XX,XX):"); //提示输入scanf("%d,%d,%d,%c",&year,&month,&day); //读入数据da=DaySearch(year,month,day); //调用DaySearch()函数来计算是星期几printf("\n%d-%d-%d is %s,do you want tocontinue?(Y/N)",year,month,day,week[da]);fflush(stdin); //刷新输入缓冲区scanf("%c",&ch);if(ch=='N'||ch=='n')break;}break;case 2: /*当为2时,进行相应运算*/while(1){printf("\nPlease input the year which needs searched?(XXXX)");scanf("%d",&year);if(IsLeapYear(year))printf("\n%d is Leap year,do you want to continue?(Y/N)",year);elseprintf("\n%d is not Leap year,do you want to continue(Y/N)?",year); fflush(stdin);scanf("%c",&ch);if(ch=='N'||ch=='n')break;}break;case 3: /*当为3时运行相应的运算*/while(1){printf("\nPlease input the year which needs printed(XXXX)");scanf("%d",&year);PrintAllYear(year);printf("\nDo you want to continue to print(Y/N)?");fflush(stdin);scanf("%c",&ch);if(ch=='N'||ch=='n')break;}break;case 4:fflush(stdin);printf("Are you sure?(Y/N)");scanf("%c",&ch);if(ch=='Y'||ch=='y')exit(1);break;default:printf("\nError:Sorry,there is no this service now!\n"); break;}}return 0;}。

C语言-万年历

C语言-万年历

#include <stdio.h>#include<time.h> //调用当前时间的头文件#include <stdlib.h>//调用清屏函数的头文件//这是一个万年历的c程序。

void Today(int year,int month,int day)//输出是星期几的函数。

{int d=0,i;int week;int a[12]={31,29,31,30,31,30,31,31,30,31,30,31};int b[12]={31,28,31,30,31,30,31,31,30,31,30,31};if(year%4==0&&year%100!=0||year%400==0)//判断是否是闰年。

{for(i=1;i<month;i++)d=d+a[i-1];}else{for(i=1;i<month;i++)d=d+b[i-1];}d=d+day;week=(year-1)*365+(year-1)/4-(year-1)/100+(year-1)/400+d;//判断这一天是星期几的公式。

week=week%7;//判断这一天是星期几的公式。

当week=0,表示星期日。

//下面是输出星期。

switch(week){case 1:printf("\t%d 年%d 月%d 日是星期: 一",year,month,day);break;case 2:printf("\t%d 年%d 月%d 日是星期: 二",year,month,day);break;case 3:printf("\t%d 年%d 月%d 日是星期: 三",year,month,day);break;case 4:printf("\t%d 年%d 月%d 日是星期: 四",year,month,day);break;case 5:printf("\t%d 年%d 月%d 日是星期: 五",year,month,day);break;case 6:printf("\t%d 年%d 月%d 日是星期: 六",year,month,day);break;case 0:printf("\t%d 年%d 月%d 日是星期: 日",year,month,day);break;}printf("\n\n");}void Tomonth(int year,int month)//输入日历的函数{int week;int t=1;int d=0,i;int a[12]={31,29,31,30,31,30,31,31,30,31,30,31};int b[12]={31,28,31,30,31,30,31,31,30,31,30,31};//这个if和for是计算d的值,d表示到今天为止总共的天数。

(完整版)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语言万年历(代码+说明)

/*本程序在Microsoft Visual Studio 2010 旗舰版中测试通过*/ #include "stdio.h"#include "stdlib.h"#include "time.h"#include "conio.h"#define KEYUP 72//宏定义键盘的键值(↑)#define KEYDOWN 80//宏定义键盘的键值(↓)#define KEYLEFT 75//宏定义键盘的键值(←)#define KEYRIGHT 77//宏定义键盘的键值(→)//函数声明部分const int isLeap(int year);const int getMonthDays(int year,int month);const int yearDays(int year);void printCalendar(int year,int month);void main(){int year,month;int action = 0;//获取本地当前的年份和月份time_t timep;struct tm *p;time(&timep);p = localtime(&timep);year = p->tm_year+1900;//获取本地当前的年份month = p->tm_mon + 1;//获取本地当前的月份while(1){printf("\t\t %d 年%d 月\n",year,month);printCalendar(year,month);action = getch();system("cls");switch(action){case KEYUP:year++;break;case KEYDOWN:year--;break;case KEYLEFT:month--;if(month < 1){month = 12;}break;case KEYRIGHT:month++;if(month > 12){month = 1;}break;}}}//判断year 是否是润年返回1 为闰年const int isLeap(int year){if(year%4==0&&year%100!=0||year%400==0){ return 1;}else{return 0;}}/*计算year 年的month 月是多少天*返回值:整型,天数*/const int getMonthDays(int year,int month){ switch(month){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(isLeap(year)){return 29;}else{return 28;}break;default:return 0;break;}}//计算year 年的天数const int yearDays(int year){if(isLeap(year)){return 366;}else{return 365;}}/*判断year 年month 月day 天时星期几*返回值:0,1,2,3,4,5,6*/const int isWeek(int year,int month,int day){ int days = 0;int i;//计算前year 年有多少天for(i=1;i<year;i++){days = days + yearDays(i);}//计算year 年的前month 个月有多少天for(i=1;i<month;i++){days = days + getMonthDays(year,i);}//从公元1 年days = days + day;return days%7;}//按日历的格式打印year 年month 月的日历void printCalendar(int year,int month){const char *week[]= {"日","一","二","三","四","五","六"};int i;int row = 0;for(i=0;i<7;i++){printf("%s\t",week[i]);}printf("\n");//判断year 年month 月1 日时星期几for(i=0;i<isWeek(year,month,1);i++){printf("\t");}for(i=0;i<getMonthDays(year,month);i++){ printf("%d\t",i+1);//如果是星期六就换行打印日期if(isWeek(year,month,i+1) == 6){row ++;if(row == 2){printf(" ↑");}if(row == 3){printf("←→");}if(row == 4){printf(" ↓");}printf("\n\n");}}printf("\n");}CreateDBW制作2012年12月7日。

万年历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>// 函数声明int is_leap_year(int year);int get_first_day_of_year(int year);// 主函数int main() {int year, month, first_day_of_year, first_day_of_month, days_in_month;int i, j, k;printf("请输入年份(例如:2022):");scanf("%d", &year);first_day_of_year = get_first_day_of_year(year);for (month = 1; month <= 12; month++) {printf("%d 年%d 月\n", year, month);printf("日一二三四五六\n");if (month == 2) {if (is_leap_year(year)) {days_in_month = 29;} else {days_in_month = 28;}} else if (month == 4 || month == 6 || month == 9 || month == 11) { days_in_month = 30;} else {days_in_month = 31;}first_day_of_month = (first_day_of_year + (month-1)*28)%7;for (i = 1; i <= first_day_of_month; i++) {printf(" ");}for (j = 1; j <= days_in_month; j++) {printf("%2d ", j);k = (i + j - 1) % 7;if (k == 0) {printf("\n");}}printf("\n");}}// 判断是否闰年int is_leap_year(int year) {return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);}// 计算年份第一天是星期几int get_first_day_of_year(int year) {int first_day = (year - 1) * 365 + (year - 1) / 4 - (year - 1) / 100 + (year - 1) / 400;first_day = (first_day + 1) % 7;return first_day;}这是一个简单的万年历示例代码,但它不是完整的代码。

c程序万年历编写

c程序万年历编写

C程序万年历编写#include<stdio.h>int main(){int choice;do{system("cls");printf("*********************************\n");printf("* 请选择你要的查询方式! *\n");printf("*1、输入一年的年份输出全年的日历*\n");printf("*2、输入年份、月份输出该月的日历*\n");printf("*3、输入月日,计算出该天是星期几*\n");printf("*0、Exit! *\n");printf("*********************************\n");scanf("%d",&choice);switch(choice){case 1:oneyear();system("pause");break;/*函数调用*/case 2:onemonth();system("pause");break;case 3:oneday();system("pause");break;case 0:break;}if(choice==0)break;}while(1);}/以mina()是主函数,分别对三个函数oneyear()、onemonth()、oneday()的调用/void oneyear(){int year,month, yearday,monthday,i,day,week;do{printf("请输入1980年以后的年份!\n");printf("输入你要查询的年份!\n");scanf("%d",&year);if(year<1980)printf("你输入的年份有误,请正确输入!\n");elsebreak;}while(1);for(i=1980,yearday=0; i<year; i++)/*计算所有年份的天数*/{yearday=yearday+365;if((i%4==0&&i%100!=0)||(i%400==0))/*判断闰年平年*/yearday++;}for(month=1; month<=12; month++){printf("\n%d月份\n",month);printf(" SUN MON TUE WED THU FRI SAT\n");switch(month){case 2:{if((year%4==0&&year%100!=0)||(year%400==0)) day=29;elseday=28;}break;case 4:case 6:case 9:case 11:day=30;break;default :day=31;}week=(yearday+1+1)%7;/*判断该年的一月一日是周几*/ yearday += day;for ( i = 0; i <week; ++i )printf(" ");for(monthday=1; monthday<=day; monthday++){if(week==7){printf("\n");week=0;}printf("%6d",monthday);if(monthday==day)printf("\n");week++;}}}void onemonth(){int month,day,monthday,year,yearday,totaday,i,n,week,sum;do{printf("输入1980年以后的年份!\n");printf("输入年份、月份:\n");scanf("%d,%d",&year,&month);if(year<1980)printf("你输入的有误,请重新输入!\n");elsebreak;}while(1);printf(" SUN MON TUE WED THU FRI SAT\n");yearday=0;for(i=1980; i<year; i++){yearday=yearday+365;if((i%4==0&&i%100!=0)||(i%400==0))}for(sum=0,n=1;n<month;n++){switch(n){case 2:if((year%4==0&&year%100!=0)||(year%400==0)) day=29;elseday=28;break;case 4:case 6:case 9:case 11:day=30;break;default :day=31;}sum=day+sum;}totaday=sum+yearday;week=(totaday+1+1)%7;for ( i = 0; i<week; ++i )printf(" ");switch(month){case 2:if((year%4==0&&year%100!=0)||(year%400==0))elseday=28;break;case 4:case 6:case 9:case 11:day=30;break;default :day=31;}for(monthday=1; monthday<=day; monthday++) {if(week==7){printf("\n");week=0;}printf("%6d",monthday);if(monthday==day)printf("\n");week++;}}void oneday(){int year,month,day,yearday,totaday,monthday,n,sum,i,week; do{printf("请输入1980年以后的年份!\n");printf("请输入要查询的年月日:\n");scanf("%d,%d,%d",&year,&month,&day);if(year<1980)printf("你输入的有误,请重新输入!\n");elsebreak;}while(1);yearday=0;for(i=1980;i<year;i++){yearday=365+yearday;if((i%4==0&&i%100!=0||i%400==0))yearday++;}for(sum=0,n=1;n<month;n++){switch(n){case 2:if((year%4==0&&year%100!=0)||(year%400==0)) monthday=29;elsemonthday=28;break;case 4:case 6:case 9:case 11:monthday=30;break;default :monthday=31;}sum=monthday+sum;}totaday=sum+yearday+day;week=(totaday+1)%7;switch(week){case 1:printf("该天是周一!\n");break;case 2:printf("该天是周二!\n");break;case 3:printf("该天是周三!\n");break; case 4:printf("该天是周四!\n");break; case 5:printf("该天是周五!\n");break; case 6:printf("该天是周六!\n");break; case 0:printf("该天是周日!\n");}}。

c语言万年历

c语言万年历

#include<stdio.h>#include<conio.h>#define PF printf#define EP PF("%s%s%.10s%s%s*",s,k,k,k,k)#define LEAP(y) !(y%(y%100?4:400))int xqj(int year,int month,int day)//ĞÇÆÚ¼¸{int i,y1,days[]={0,31,28,31,30,31,30,31,31,30,31,30,31};days[2]=28+LEAP(year);for(i=1;i<month;i++)day+=days[i];y1=year-1;day+=y1+y1/4-y1/100+y1/400;return day%7;}void fill(int y,int m,char array[3*7*6]){char *pa;int i,x1,days[]={0,31,28,31,30,31,30,31,31,30,31,30,31};days[2]=28+LEAP(y);x1 = xqj(y,m,1);x1 = x1?x1-1:x1+6;pa = array+3*x1;for(i=1;i<=3*7*6;i++)array[i-1]=' ';for(i=1;i<=days[m];i++,pa+=3)sprintf(pa,"%3d",i);*pa=' ';}void half(int year,int m){int i,j;char ary[6][7*3],bry[6][7*3],cry[6][7*3];char *k=" ",*s="\n *";char *xs="********************************";PF("%s%s %04d %s*",s,xs,year,xs);for(i=1;i<=2;i++,m+=3){EP;if(m<10)PF("%s%.10s(%d)%.20s(%d)%.20s(%d)%.11s*",s,k,m,k,m+1,k,m+2 ,k);elsePF("%s%.10s(%d)%.19s(%d)%.19s(%d)%.10s*",s,k,m,k,m+1,k,m+2,k);EP;PF("%s MO TU WE TH FR SA SU MO TU WE TH FR SA SU MO TU WE TH FR SA SU *",s);fill(year,m ,ary[0]);fill(year,m+1,bry[0]);fill(year,m+2,cry[0]);for(j=0;j<6;j++){PF("%s %.21s %.21s %.21s *",s,ary[j],bry[j],cry[j]);}EP;}PF("%s%s******%s*",s,xs,xs);}main( ){int year;do{PF("year: ");scanf("%d",&year);}while(year<=0||year>9999);half(year,1);//ÉÏ°ëÄêgetch();PF("\n");half(year,7);//Ï°ëÄêgetch();PF("\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>main(){for(;;){int year,month,a,b,c,m,n=28;/*定义变量*/long e;printf("请输入年份");scanf("%d",&year);e=year;e--; /*前一年*/e=(e*365+e/4)%7; /*计算这一年的第一天是星期几*/m=e; /*把第一天的日期赋给m*/if((year%4==0)||(year%100!=0)&&(year%400!=0))/*如果是闰年*/n++;printf("%d的日历:",year);for(month=1;month<=12;month++){if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)/*这几个月每个月都是31天*/{c=0;printf("\n");printf(" %d月\n",month);printf(" 日一二三四五六\n");for(b=1;b<=m;b++){c++;printf(" ");/*从星期日开始到这个月开始的那天前都是空的*/}for(a=1;a<=31;a++){c++;if(c%7-1==0&&c!=1)/*判断一行是否已排满,满了就要换行*/printf("\n");if(a<10) /*如果是小于10,空一格,大于10,前后空*/printf(" ");printf(" %d ",a);m++;if(m==7)/*一行排满,开始换行。

(指的是这个月的最后一行)*/m=0;}printf("\n");}else{if(month==4||month==6||month==9||month==11||month==2) {if(month==2)/*判断2月份*/{c=0;printf("\n");printf(" %d月\n",month);printf(" ");printf(" 日一二三四五六\n");for(b=1;b<=m;b++){c++;printf(" ");}for(a=1;a<=n;a++){c++;if(c%7-1==0&&c!=1)printf("\n");if(a<10)printf(" ");printf(" %d ",a);m++;if(m==7)m=0;}printf("\n");}else{c=0;printf("\n");printf(" %d月\n",month);printf(" 日一二三四五六\n");for(b=1;b<=m;b++){c++;printf(" ");}for(a=1;a<=30;a++){c++;if(c%7-1==0&&c!=1)printf("\n");if(a<10)printf(" ");printf(" %d ",a);m++;if(m==7)m=0;}printf("\n");}}}}}}。

用c语言编写万年历

用c语言编写万年历

#include<stdio.h>//假设今天是2013年12月22号,是星期天,根据这个日期计算日历中的某天距离今天有多少天,且输入的日期为星期几!查表得1800年1月1日为星期三。

int i,j,k,a,b,c,w=0;//i,j,k分别代表全局变量的年月日。

int y(){int p, h=0,inleap=0,leap=0,sum=0,count1,count2,leap1;scanf("%d",&i);if(i>2100||i<1800)printf("输入的年份不合法,或者不在程序运算的范围内");else{ printf("%d年的年历为:\n",i);for(j=1;j<=12;j++){{for(a=1800;a<=i;a++){if((a%4==0&&a%100!=0)||(a%400==0))leap++;else inleap++;}count1=leap*366;count2=inleap*365;switch(j){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;}sum=sum+count1+count2;{if(i%400==0||(i%4==0&&i%100!=0))leap1=1; //如果不是闰年则直接执行elseleap1=0;if(leap1==1&&j>2) //如果是闰年并且月份大于2,总天数应该加一天sum++;}h=(sum+2)%7;}if((i%4==0&&i%100!=0)||(i%400==0)){switch(j){case 1:case 3:case 5:case 7:case 8:case 10:case 12:printf("\t\t%d月\n",j);printf("%4s%4s%4s%4s%4s%4s%4s\n","Sun","Mon","Tues","Wed","Thur","Fri","Sat");for(p=0;p<h;p++)printf(" ");for(c=1;c<=31;c++){printf("%4d",c);if((c+h)%7==0)printf("\n");}printf("\n");break;case 4:case 6:case 9:case 11:printf("\t\t%d月\n",j);printf("%4s%4s%4s%4s%4s%4s%4s\n","Sun","Mon","Tues","Wed","Thur","Fri","Sat");for(p=0;p<h;p++)printf(" ");for(c=1;c<=30;c++){printf("%4d",c);if((h+c)%7==0)printf("\n");}printf("\n");break;case 2:printf("\t\t%d月\n",j);printf("%4s%4s%4s%4s%4s%4s%4s\n","Sun","Mon","Tues","Wed","Thur","Fri","Sat");for(c=1;c<=29;c++){printf("%4d",c);if((c+h)%7==0)printf("\n");}printf("\n");}}else{switch(j){case 1:case 3:case 5:case 7:case 8:case 10:case 12:printf("\t\t%d月\n",j);printf("%4s%4s%4s%4s%4s%4s%4s\n","Sun","Mon","Tues","Wed","Thur","Fri","Sat");for(p=0;p<h;p++)printf(" ");for(c=1;c<=31;c++){printf("%4d",c);if((c+h)%7==0)printf("\n");}printf("\n");break;case 4:case 6:case 9:case 11:printf("\t\t%d月\n",j);printf("%4s%4s%4s%4s%4s%4s%4s\n","Sun","Mon","Tues","Wed","Thur","Fri","Sat");for(p=0;p<h;p++)printf(" ");for(c=1;c<=30;c++){printf("%4d",c);if((h+c)%7==0)printf("\n");}printf("\n");break;case 2:printf("%4s%4s%4s%4s%4s%4s%4s\n","Sun","Mon","Tues","Wed","Thur","Fri","Sat");printf("\t\t%d月\n",j);for(p=0;p<h;p++)printf(" ");for(c=1;c<=28;c++){printf("%4d",c);if((c+h)%7==0)printf("\n");}printf("\n");break;}}}}}int ym(){int p,h=0,inleap=0,leap=0,count,sum=0,count1,count2,leap1;scanf("%d%d",&i,&j);if(i<1800||i>2100||j<1||j>12)printf("您输入的年月份不在运算范围或者不合法,请重新输入!");else{ printf("%d年%d月的月历为:\n",i,j);{for(a=1800;a<i;a++){if((a%4==0&&a%100!=0)||(a%400==0))leap++;else inleap++;}count1=leap*366;count2=inleap*365;switch(j){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;}sum=sum+count1+count2;{if(i%400==0||(i%4==0&&i%100!=0))leap1=1; //如果不是闰年则直接执行elseleap1=0;if(leap==1&&j>2) //如果是闰年并且月份大于2,总天数应该加一天sum++;}h=(sum+3)%7;}if((i%4==0&&i%100!=0)||(i%400==0)){switch(j){case 1:case 3:case 5:case 7:case 8:case 10:case 12:printf("\t\t%d月\n",j);printf("%4s%4s%4s%4s%4s%4s%4s\n","Sun","Mon","Tues","Wed","Thur","Fri","Sat");for(p=0;p<h;p++)printf(" ");for(c=1;c<=31;c++){printf("%4d",c);if((c+h)%7==0)printf("\n");}printf("\n");break;case 4:case 6:case 9:case 11:printf("\t\t%d月\n",j);printf("%4s%4s%4s%4s%4s%4s%4s\n","Sun","Mon","Tues","Wed","Thur","Fri","Sat");for(p=0;p<h;p++)printf(" ");for(c=1;c<=30;c++){printf("%4d",c);if((h+c)%7==0)printf("\n");}printf("\n");break;case 2:printf("\t\t%d月\n",j);printf("%4s%4s%4s%4s%4s%4s%4s\n","Sun","Mon","Tues","Wed","Thur","Fri","Sat");for(c=1;c<=29;c++){printf("%4d",c);if((c+h)%7==0)printf("\n");}printf("\n");break;}}else{switch(j){case 1:case 3:case 5:case 7:case 8:case 10:case 12:printf("%4s%4s%4s%4s%4s%4s%4s\n","Sun","Mon","Tues","Wed","Thur","Fri","Sat");printf("\t\t%d月\n",j);for(p=0;p<h;p++)printf(" ");for(c=1;c<=31;c++){printf("%4d",c);if((c+h)%7==0)printf("\n");}printf("\n");break;case 4:case 6:case 9:case 11:printf("%4s%4s%4s%4s%4s%4s%4s\n","Sun","Mon","Tues","Wed","Thur","Fri","Sat");printf("\t\t%d月\n",j);for(p=0;p<h;p++)printf(" ");for(c=1;c<=30;c++){printf("%4d",c);if((h+c)%7==0)printf("\n");}printf("\n");break;case 2:printf("%4s%4s%4s%4s%4s%4s%4s\n","Sun","Mon","Tues","Wed","Thur","Fri","Sat");printf("\t\t%d月\n",j);for(p=0;p<h;p++)printf(" ");for(c=1;c<=28;c++){printf("%4d",c);if((c+h)%7==0)printf("\n");}printf("\n");}}}}int ymd(){int sum=0,leap=0,inleap=-1,leap1,count1=1,count2=1,count3=356,count4,count;//其中的lead代表是从当年到今年的闰年数,count1则为闰年的总天数,//inlead代表的是从当年日期到今年的日期的平年数,count2则为平年的总天数,count3则为今年的第N天,count4则为当年的倒数第N天。

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

//任务五:万年历程序#include<stdio.h>#include<stdlib.h>#include<string.h>void DataTrans(char *chDate,int *nY ear,int *nMonth,int *nDay);int IsLeapY ear(int nY ear);int GetWeekOfFirstday(int nY ear);int GetWeek(int nY ear,int nMonth,int nDay,int nWeekOfFirstday);void PrintCalendar(int nWeek,int nDay,int nMonthDays,char *chDate);int nDaysY ear[]={31,28,31,30,31,30,31,31,30,31,30,31};int nDaysLeapY ear[]={31,29,31,30,31,30,31,31,30,31,30,31};main(int argc,char *argv[]){char chDate[11];//输入查询日期int nY ear=0,nMonth=0,nDay=0;////查询日期对应的年、月、日int nWeekOfFirstday;//查询年的1月1日是周几int nDaysOfMonth;//查询当月总天数int nWeek;//查询日是周几if(argc>1){strcpy(chDate,argv[1]);}else{printf("Please enter the date(YYYY/MM/DD or YYYY.MM.DD or YYYY/MM or YYYY.MM):\n");gets(chDate);}DataTrans(chDate,&nY ear,&nMonth,&nDay);if(nY ear<=0||nMonth<1||nMonth>12){printf("Input error!\n");exit(0);}if(IsLeapY ear(nY ear)){nDaysOfMonth=nDaysLeapYear[nMonth-1];}else{nDaysOfMonth=nDaysY ear[nMonth-1];}nWeekOfFirstday=GetWeekOfFirstday(nY ear);if(strlen(chDate)==10){nWeek=GetWeek(nY ear,nMonth,nDay,nWeekOfFirstday);if(nDay<1||nDay>nDaysOfMonth){printf("Input error!\n");exit(0);}}if(strlen(chDate)==7){nWeek=GetWeek(nY ear,nMonth,1,nWeekOfFirstday);}PrintCalendar(nWeek,nDay,nDaysOfMonth,chDate);}void DataTrans(char *chDate,int *nY ear,int *nMonth,int *nDay)//将字符串表示的日期变换为整数分别表示的年、月、日{*nY ear=(chDate[0]-'0')*1000+(chDate[1]-'0')*100+(chDate[2]-'0')*10+(chDate[3]-'0');*nMonth=(chDate[5]-'0')*10+(chDate[6]-'0');*nDay=(chDate[8]-'0')*10+(chDate[9]-'0');}int IsLeapY ear(int nY ear)//判断给定的年份是否是闰年{if(((nY ear%4==0)&&(nY ear%100!=0))||(nY ear%400==0))return 1;elsereturn 0;}int GetWeekOfFirstday(int nY ear)//查询年nY ear1月1日是周几{int i,m,n,temp;if(nY ear==2000){return 6;}else if(nY ear>2000){i=nY ear-2000;if(i==1){temp=(366+1-2)%7;if(temp==0)return (temp+7);elsereturn temp;}else{m=(i-1)/4;n=(i-1)%4;temp=(366+(365*3+366)*m+365*n+1-2)%7;if(temp==0)return (temp+7);elsereturn temp;}}else{i=2000-nY ear;m=i/4;n=i%4;temp=((365*3+366)*m+365*n+2)%7;if(temp==0)return 1;elsereturn (8-temp);}}int GetWeek(int nY ear,int nMonth,int nDay,int nWeekOfFirstday)//查询日是周几{int sum;int i,j;sum=nDay;if(IsLeapY ear(nY ear)){for(i=0;i<(nMonth-1);i++){sum+=nDaysLeapY ear[i];}sum=(sum-1)%7;sum+=nWeekOfFirstday;if(sum>7)return (sum-7);elsereturn sum;}else{for(i=0;i<(nMonth-1);i++){sum+=nDaysY ear[i];}sum=(sum-1)%7;sum+=nWeekOfFirstday;if(sum>7)return (sum-7);elsereturn sum;}}void PrintCalendar(int nWeek,int nDay,int nMonthDays,char *chDate)//根据查询日、星期几打印日历{int i,j;if(strlen(chDate)==7){printf("The calendar of this month as following:\n");printf("*********************************\n");printf("SUN MON TUE WEN THE FRI STA\n");if(nWeek==7){for(i=1;i<=nMonthDays;i++){printf("%2d ",i);if(i%7==0)printf("\n");}if(i!=28)printf("\n");}else{for(j=0;j<5*nWeek;j++){printf(" ");}for(i=1;i<=nMonthDays;i++){printf("%2d ",i);if((i-(7-nWeek))%7==0)printf("\n");}if((nMonthDays-(8-nWeek))%7!=6)printf("\n");}printf("*********************************\n");printf("OK!\n");}if(strlen(chDate)==10){printf("This day (");printf("%s",chDate);printf(") is ");switch(nWeek){case 1:printf("MONDAY(1)\n");break;case 2:printf("THESDAY(2)\n");break;case 3:printf("WEDNESDAY(3)\n");break;case 4:printf("THURDAY(4)\n");break;case 5:printf("FRIDA Y(5)\n");break;case 6:printf("SA TURDAY(6)\n");break;case 7:printf("SUNAY(7)\n");break;default:printf("error!\n");exit(0);}printf("OK!\n");}}。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
printf("\nDo you want to continue to print(Y/N)?");
fflush(stdin);
scanf("%c",&ch);
if(ch=='N'||ch=='n')
break;
}
break;
case 4:
fflush(stdin);
printf("Are you sure?(Y/N)");
char* week[]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
int leap (int year)//判断闰年
{
if(year%4==0&&year%100!=0||year%400==0)
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**************");
}
for(i=1;i<=b;i++)
{
printf("%4d",i);
if(i==7*k-a)
{
printf("\n");
k++;
}
}
}
printf("\n");
//******************************************************************
while(1)
{
printf("\n请选择你所需要的服务:\n");
printf("\n输入1求某个日期对应的星期");
printf("\n输入2判断某年是否为闰年");
printf("\n输入3输出某年的日历");
printf("\n输入4结束程序\n");
scanf("%d",&option);
switch(option)
/* welcome to use the WanNianLi system! */
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
char* month_str[]={"January","February","March","April","May","June","July","August","September","October","November","December"};
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++;
scanf("%c",&ch);
if(ch=='N'||ch=='n')
break;
}
break;
case 3:
while(1)
{
printf("\nPlease input the year which needs printed(XXXX)");
scanf("%d",&year);
PrintAllYear(year);
int i,j=1,n=1,k;
printf("\n\n**************%d年的挂历**************\n",year);
for(k=1;k<=12;k++)
{
j=1,n=1;
b=month_day(year,k);
a=firstday(year,k,1);
printf("\n\n%s(%d)\n",month_str[k-1],k);
c=c+day;
s=year-1+(float)(year-1)/4+(float)(year-1)/100+(float)(year-1)/400-40+c;
return ((int)s%7);
}
int PrintAllYear(int year)/*print the all year*/
{
int a,b;
fflush(stdin);
scanf("%c",&ch);
if(ch=='N'||ch=='n')
break;
}
break;
case 2:
while(1)
{
printf("\nPlease input the year which needs searched?(XXXX)");
scanf("%d",&year);
{
case 1:
while(1)
{
printf("\nPlease input the year,month and day(XXXX,XX,XX):");
scanf("%d,%d,%d,%c",&year,&month,&day);
da=firstday(year,month,day);
printf("\n%d-%d-%d is %s,do you want to continue?(Y/N)",year,month,day,week[da]);
//调用结束
int i,j=1,k=1;
int a,b;
b=month_day(now->tm_year+1900,now->tm_mon+1);
a=firstday (now->tm_year+1900,now->tm_mon+1,now->tm_mday);
printf("\n%d\n%d\n",b,a);
return 1;
else return 0;
}
int month_day(int year,int month) //判断这一个月有多少天
{
int mon_day[]={31,28,31,30,31,30,31,31,30,31,30,31}; //初始化每个月的天数
if(leap(year)&&month==2 )
}
return 1;
}
//****************************************************
int main()
{
int option,da;
char ch;
int year,month,day;
printf("Copyright @ 2005 TianQian All rights reserved!:):):)");
}
}
}
if(a!=7)
{
while (j<=4*a)
{
printf(" ");
j++;
}
for(i=1;i<=b;i++)
{
printf("%4d",i);
if(i==7*n-a)
{
printf("**************\n**************");
n++;
}
}
}
printf("******ห้องสมุดไป่ตู้*******\n");
scanf("%c",&ch);
if(ch=='Y'||ch=='y')
exit(0);
break;
default:
printf("\nError:Sorry,there is no this service now!\n");
break;
}
}
return 0;
}
return 29;
else
return(mon_day[month-1]);
}
int firstday(int year,int month,int day)//判断这一个月的第一天是星期几
{
相关文档
最新文档