C 万年历及公历农历转换源代码1
合集下载
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
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;
{
case 1:rli();break;
case 2:gongli();break;
case 3:nongli();break;
ca;); \n");
\n"); \n");
/*打印公历年历函数*/ 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; } }
printf("\n
1.The calendar of the year
printf("\n
2.gongli zhuanhuan nongli
printf("\n
3.nongli zhuanhuan gongli
printf("\n
4.exit
\n");
scanf("%d",&cd);
switch(cd)
/*如果是闰年&&月份大于二则在该公历年的第几天数+1*/ gong_chunjie=whatday-(whatChunJie-1); /*差值=输入的公历日期-春节在公历年的第几天 -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/100>2)) whatChunJie++;
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/*主函数*/
main()
{
int cd;
for(;;)
{
clrscr();
printf("\n\n\n\n\n\n\n\n");
printf("
Please Choose Operations
case 11:printf("
* 11 * "); break;
}
printf("
");
switch(i+1)
{case 2:printf(" * 2 *");break;
case 4:printf(" * 4 *");break;
case 6:printf(" * 6 *");break;
case 8:printf(" * 8 *"); break;
500D2,0xB550781,0x6CA00D9, 0xB5500CE,0x535157F,0x4DA00D6,0xA5B00CB,0x457037C,0x52B00D4,0xA9A0883,0xE950 0DA,0x6AA00D0,0xAEA0680, 0xAB500D7,0x4B600CD,0xAAE047D,0xA5700D5,0x52600CA,0xF260379,0xD9500D1,0x5B5 0782,0x56A00D9,0x96D00CE, 0x4DD057F,0x4AD00D7,0xA4D00CB,0xD4D047B,0xD2500D3,0xD550883,0xB5400DA,0xB6 A00CF,0x95A1680,0x95B00D8, 0x49B00CD,0xA97047D,0xA4B00D5,0xB270ACA,0x6A500DC,0x6D400D1,0xAF40681,0xAB 600D9,0x93700CE,0x4AF057F, 0x49700D7,0x64B00CC,0x74A037B,0xEA500D2,0x6B50883,0x5AC00DB,0xAB600CF,0x96D 0580,0x92E00D8,0xC9600CD, 0xD95047C,0xD4A00D4,0xDA500C9,0x755027A,0x56A00D1,0xABB0781,0x25D00DA,0x92D 00CF,0xCAB057E,0xA9500D6, 0xB4A00CB,0xBAA047B,0xB5500D2,0x55D0983,0x4BA00DB,0xA5B00D0,0x5171680,0x52B 00D8,0xA9300CD,0x795047D, 0x6AA00D4,0xAD500C9,0x5B5027A,0x4B600D2,0x96E0681,0xA4E00D9,0xD2600CE,0xEA6 057E,0xD5300D5,0x5AA00CB, 0x76A037B,0x96D00D3,0x4AB0B83,0x4AD00DB,0xA4D00D0,0xD0B1680,0xD2500D7,0xD5 200CC,0xDD4057C,0xB5A00D4, 0x56D00C9,0x55B027A,0x49B00D2,0xA570782,0xA4B00D9,0xAA500CE,0xB25157E,0x6D20 0D6,0xADA00CA,0x4B6137B, 0x93700D3,0x49F08C9,0x49700DB,0x64B00D0,0x68A1680,0xEA500D7,0x6AA00CC,0xA6C1 47C,0xAAE00D4,0x92E00CA, 0xD2E0379,0xC9600D1,0xD550781,0xD4A00D9,0xDA400CD,0x5D5057E,0x56A00D6,0xA6C 00CB,0x55D047B,0x52D00D3, 0xA9B0883,0xA9500DB,0xB4A00CF,0xB6A067F,0xAD500D7,0x55A00CD,0xABA047C,0xA5 A00D4,0x52B00CA,0xB27037A, 0x69300D1,0x7330781,0x6AA00D9,0xAD500CE,0x4B5157E,0x4B600D6,0xA5700CB,0x54E0 47C,0xD1600D2,0xE960882, 0xD5200DA,0xDAA00CF,0x6AA167F,0x56D00D7,0x4AE00CD,0xA9D047D,0xA2D00D4,0xD 1500C9,0xF250279,0xD5200D1 };
const long NongliData[202]={0xAB500D2,0x4BD0883, 0x4AE00DB,0xA5700D0,0x54D0581,0xD2600D8,0xD9500CC,0x655147D,0x56A00D5,0x9AD 00CA,0x55D027A,0x4AE00D2, 0xA5B0682,0xA4D00DA,0xD2500CE,0xD25157E,0xB5500D6,0x56A00CC,0xADA027B,0x95 B00D3,0x49717C9,0x49B00DC, 0xA4B00D0,0xB4B0580,0x6A500D8,0x6D400CD,0xAB5147C,0x2B600D5,0x95700CA,0x52F 027B,0x49700D2,0x6560682, 0xD4A00D9,0xEA500CE,0x6A9157E,0x5AD00D6,0x2B600CC,0x86E137C,0x92E00D3,0xC8D 1783,0xC9500DB,0xD4A00D0, 0xD8A167F,0xB5500D7,0x56A00CD,0xA5B147D,0x25D00D5,0x92D00CA,0xD2B027A,0xA9
{if(j==0){print(d*4); for(k=0;k<d*4;k++) ;
for(k=0;k<7-d;k++) {printf("%4d",++m); }
printf("
");
d+=a[i]%7; d%=7;
print(d*4);
for(k=0;k<d*4;k++) ;
for(k=0;k<7-d;k++)
printf("
The calendar of the year %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)
/*公历转换农历*/ gongli() {
int gyear,gmonth,gday; static int whatday,a,b,whatChunJie,gong_chunjie,Znongwhatday; static int nYear,nMonth,nDay,runmonth,runday,YNrun=0,runt; long int ChunJieYear; long int c; int wei,wei1,cz,cz1,nm,mt,i,i1; clrscr(); printf("输入需查询的公历年月日 (例:2005.05.25):\n");
rli()
{int i,j,k,m,n,f1,f2,year,d;
int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
printf("\n Please input the year:");
scanf("%d",&year);
printf("\n\n");
{if(n<a[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();
{
printf("%4d",++n);
}
printf("\n");;
}
else{for(k=0;k<7;k++)
{if(m<a[i])
{printf("%4d",++m); }
else {printf(" "); }
if(m==a[i]) f1=1;
}
printf("
");
for(k=0;k<7;k++)
case 10:printf(" * 10 *"); break;
case 12:printf(" * 12 *"); break;
}
printf("\n");
printf(" SU MO TU WE TH FR SA
SU MO TU WE TH FR
SA");
printf("\n");
for(j=0;j<6;j++)