您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 综合/其它 > c++万年历及公历农历转换源代码1
#includestdio.h#includestdlib.h#includemath.h/*主函数*/main(){intcd;for(;;){clrscr();printf(\n\n\n\n\n\n\n\n);printf(PleaseChooseOperations\n);printf(\n1.Thecalendaroftheyear\n);printf(\n2.gonglizhuanhuannongli\n);printf(\n3.nonglizhuanhuangongli\n);printf(\n4.exit\n);scanf(%d,&cd);switch(cd){case1:rli();break;case2:gongli();break;case3:nongli();break;case4:exit(0);}}}/*打印公历年历函数*/print(intn){inti;for(i=0;in;i++)printf();}intday(intyear){longa,b;if(year=2000){a=2000-year;b=6-(a+a/4-a/100+a/400)%7;returnb;}else{a=year-2000;b=(a+1+(a-1)/4-(a-1)/100+(a-1)/400)%7+6;returnb%7;}}rli(){inti,j,k,m,n,f1,f2,year,d;inta[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};printf(\nPleaseinputtheyear:);scanf(%d,&year);printf(\n\n);printf(Thecalendaroftheyear%d\n,year);d=day(year);if(year%4==0&&year%100||year%400==0)a[2]++;for(i=1;i=12;i+=2){m=0;n=0;f1=0;f2=0;switch(i){case1:printf(*1*);break;case3:printf(*3*);break;case5:printf(*5*);break;case7:printf(*7*);break;case9:printf(*9*);break;case11:printf(*11*);break;}printf();switch(i+1){case2:printf(*2*);break;case4:printf(*4*);break;case6:printf(*6*);break;case8:printf(*8*);break;case10:printf(*10*);break;case12:printf(*12*);break;}printf(\n);printf(SUMOTUWETHFRSASUMOTUWETHFRSA);printf(\n);for(j=0;j6;j++){if(j==0){print(d*4);for(k=0;kd*4;k++);for(k=0;k7-d;k++){printf(%4d,++m);}printf();d+=a[i]%7;d%=7;print(d*4);for(k=0;kd*4;k++);for(k=0;k7-d;k++){printf(%4d,++n);}printf(\n);;}else{for(k=0;k7;k++){if(ma[i]){printf(%4d,++m);}else{printf();}if(m==a[i])f1=1;}printf();for(k=0;k7;k++){if(na[i+1]){printf(%4d,++n);}else{printf();}if(n==a[i+1])f2=1;}printf(\n);if(f1&&f2)break;}}d+=a[i+1]%7;d%=7;printf();if(i==5){getch();clrscr();}}getch();}/*公历每月前面的天数*/constintgPastday[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};constlongNongliData[202]={0xAB500D2,0x4BD0883,0x4AE00DB,0xA5700D0,0x54D0581,0xD2600D8,0xD9500CC,0x655147D,0x56A00D5,0x9AD00CA,0x55D027A,0x4AE00D2,0xA5B0682,0xA4D00DA,0xD2500CE,0xD25157E,0xB5500D6,0x56A00CC,0xADA027B,0x95B00D3,0x49717C9,0x49B00DC,0xA4B00D0,0xB4B0580,0x6A500D8,0x6D400CD,0xAB5147C,0x2B600D5,0x95700CA,0x52F027B,0x49700D2,0x6560682,0xD4A00D9,0xEA500CE,0x6A9157E,0x5AD00D6,0x2B600CC,0x86E137C,0x92E00D3,0xC8D1783,0xC9500DB,0xD4A00D0,0xD8A167F,0xB5500D7,0x56A00CD,0xA5B147D,0x25D00D5,0x92D00CA,0xD2B027A,0xA9500D2,0xB550781,0x6CA00D9,0xB5500CE,0x535157F,0x4DA00D6,0xA5B00CB,0x457037C,0x52B00D4,0xA9A0883,0xE9500DA,0x6AA00D0,0xAEA0680,0xAB500D7,0x4B600CD,0xAAE047D,0xA5700D5,0x52600CA,0xF260379,0xD9500D1,0x5B50782,0x56A00D9,0x96D00CE,0x4DD057F,0x4AD00D7,0xA4D00CB,0xD4D047B,0xD2500D3,0xD550883,0xB5400DA,0xB6A00CF,0x95A1680,0x95B00D8,0x49B00CD,0xA97047D,0xA4B00D5,0xB270ACA,0x6A500DC,0x6D400D1,0xAF40681,0xAB600D9,0x93700CE,0x4AF057F,0x49700D7,0x64B00CC,0x74A037B,0xEA500D2,0x6B50883,0x5AC00DB,0xAB600CF,0x96D0580,0x92E00D8,0xC9600CD,0xD95047C,0xD4A00D4,0xDA500C9,0x755027A,0x56A00D1,0xABB0781,0x25D00DA,0x92D00CF,0xCAB057E,0xA9500D6,0xB4A00CB,0xBAA047B,0xB5500D2,0x55D0983,0x4BA00DB,0xA5B00D0,0x5171680,0x52B00D8,0xA9300CD,0x795047D,0x6AA00D4,0xAD500C9,0x5B5027A,0x4B600D2,0x96E0681,0xA4E00D9,0xD2600CE,0xEA6057E,0xD5300D5,0x5AA00CB,0x76A037B,0x96D00D3,0x4AB0B83,0x4AD00DB,0xA4D00D0,0xD0B1680,0xD2500D7,0xD5200CC,0xDD4057C,0xB5A00D4,0x56D00C9,0x55B027A,0x49B00D2,0xA570782,0xA4B00D9,0xAA500CE,0xB25157E,0x6D200D6,0xADA00CA,0x4B6137B,0x93700D3,0x49F08C9,0x49700DB,0x64B00D0,0x68A1680,0xEA500D7,0x6AA00CC,0xA6C147C,0xAAE00D4,0x92E00CA,0xD2E0379,0xC9600D1,0xD550781,0xD4A00D9,0xDA400CD,0x5D5057E,0x56A00D6,0xA6C00CB,0x55D047B,0x52D00D3,0xA9B0883,0xA9500DB,0xB4A00CF,0xB6A067F,0xAD500D7,0x55A00CD,0xABA047C,0xA5A00D4,0x52B00CA,0xB27037A,0x69300D1,0x7330781,0x6AA00D9,0xAD500CE,0x4B5157E,0x4B600D6,0xA5700CB,0x54E047C,0xD1600D2,0xE960882,0xD5200DA,0xDAA00CF,0x6AA167F,0x56D00D7,0x4AE00CD,0xA9D047D,0xA2D00D4,0xD1500C9,0xF250279,0xD5200D1};/*公历转换农历*/gongli(){intgyear,gmonth,gday;staticintwhatday,a,b,whatChunJie,gong_chunjie,Znongwhatday;staticintnYear,nMonth,nDay,runmonth,runday,YNrun=0,runt;longintChunJieYear;longintc;intwei,wei1,cz,cz1,nm,mt,i,i1;clrscr();printf(输入需查询的公历年月日(例:2005.05.25):\n);scanf(%d.%d.%d,&gyear,&gmonth,&gday);if(gyear%4==0&&gyear%100!=0||gyear%400==0)months[2]=29;elsemonths[2]=28;/*以下是计算在该公历年的第几天*/whatday=gPastday[gmonth]+gday;if((gyear%4==0&&gyear%100!=0||gyear%400==0)&&(gmonth2))whatday++;/*上如果是闰年和月份大于二则在该公历年的第几天数+1*//*计算该年春节在公历年的第几天*/ChunJieYear=NongliData[gyear-1899];/*ChunJieYear春节的农历数据*/b=0x100;a=ChunJieYear%b;/*取出春节在公历几月几日的十六进制数*/whatChunJie=gPastday[a/100]+a%100;/*春节在公历年的第几天=月的天数+日数*/if((ChunJieYear%4==0&&ChunJieYear%100!=0||ChunJieYear%400==0)&&(a/1002))whatChunJie++;/*如果是闰年&&月份大于二则在该公历年的第几天数+1*/gong_chunjie=whatday-(whatChunJie-1);/*差值=输入的公历日期-春节在公历年的第几天-1*/if(gong_chunjie0){nYear=gyear;Znongwhatday=gong_chunjie;/*变量Znongwhatday输入的公历日期在农历年第几天*/}/*由差值判断农历年nYear*/else{nYear=gyear-1;Znongwhatday=gong_chunjie;/*变量Znongwhatday输入的公历日期在农历年第几天*/}runday=(NongliData[nYear-1899]/0x1000)%0x10;/*取出判断闰月天数的值*/runmonth=(No
本文标题:c++万年历及公历农历转换源代码1
链接地址:https://www.777doc.com/doc-4220471 .html