完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
#include
#include #include unsigned int solar_year=0,lunar_year=0; unsigned char solar_month=0,lunar_month=0; unsigned int solar_day=0,lunar_day=0; /*1900-2050年的农历数据 数据格式说明: 5位十六进制数字 例:04bd8 1 位: 1表示闰月30天,0表示29天 2、3、4位: 转换二进制为:0100 1011 1101(1为30天,0为29天) 04bd8表示为(13个月):29,30,29,29,30,29,30,30,30(闰8月),30,30,29,30; 5 位: 如果有闰月,则为月份,没有则为0*/ unsigned long int lunar_info[]= { 0x04bd8,0x04ae0,0x0a570,0x054d5,0x0d260,0x0d950,0x16554,0x056a0,0x09ad0,0x055d2, 0x04ae0,0x0a5b6,0x0a4d0,0x0d250,0x1d255,0x0b540,0x0d6a0,0x0ada2,0x095b0,0x14977, 0x04970,0x0a4b0,0x0b4b5,0x06a50,0x06d40,0x1ab54,0x02b60,0x09570,0x052f2,0x04970, 0x06566,0x0d4a0,0x0ea50,0x06e95,0x05ad0,0x02b60,0x186e3,0x092e0,0x1c8d7,0x0c950, 0x0d4a0,0x1d8a6,0x0b550,0x056a0,0x1a5b4,0x025d0,0x092d0,0x0d2b2,0x0a950,0x0b557, 0x06ca0,0x0b550,0x15355,0x04da0,0x0a5b0,0x14573,0x052b0,0x0a9a8,0x0e950,0x06aa0, 0x0aea6,0x0ab50,0x04b60,0x0aae4,0x0a570,0x05260,0x0f263,0x0d950,0x05b57,0x056a0, 0x096d0,0x04dd5,0x04ad0,0x0a4d0,0x0d4d4,0x0d250,0x0d558,0x0b540,0x0b6a0,0x195a6, 0x095b0,0x049b0,0x0a974,0x0a4b0,0x0b27a,0x06a50,0x06d40,0x0af46,0x0ab60,0x09570, 0x04af5,0x04970,0x064b0,0x074a3,0x0ea50,0x06b58,0x055c0,0x0ab60,0x096d5,0x092e0, 0x0c960,0x0d954,0x0d4a0,0x0da50,0x07552,0x056a0,0x0abb7,0x025d0,0x092d0,0x0cab5, 0x0a950,0x0b4a0,0x0baa4,0x0ad50,0x055d9,0x04ba0,0x0a5b0,0x15176,0x052b0,0x0a930, 0x07954,0x06aa0,0x0ad50,0x05b52,0x04b60,0x0a6e6,0x0a4e0,0x0d260,0x0ea65,0x0d530, 0x05aa0,0x076a3,0x096d0,0x04bd7,0x04ad0,0x0a4d0,0x1d0b6,0x0d250,0x0d520,0x0dd45, 0x0b5a0,0x056d0,0x055b2,0x049b0,0x0a577,0x0a4b0,0x0aa50,0x1b255,0x06d20,0x0ada0, 0x14b63 }; unsigned char get_leap_month(unsigned int lunar_year) { return lunar_info[lunar_year-1900]&0xf; } unsigned char get_leap_month_day(unsigned int lunar_year) { if(get_leap_month(lunar_year)) return( ( (lunar_info[lunar_year-1900]) & 0x10000 ) ? 30:29 ); else return(0); } unsigned char get_lunar_month_total(unsigned int lunar_year, unsigned char lunar_month) { return( (lunar_info[lunar_year-1900] & (0x10000>>lunar_month) ) ? 30:29 ); } unsigned int get_lunar_year_total(unsigned int lunar_year) { unsigned int sum=348; unsigned int i; for(i=0x8000;i>0x8; i>>=1) sum+=(lunar_info[lunar_year-1900]&i)?1:0; return(sum+get_leap_month_day(lunar_year)); } unsigned int leap(unsigned int year) { if( (year%4==0 &&year%100!=0) || year%400==0 ) return 366; else return 365; } unsigned char day(unsigned int year ,unsigned char month) { 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)==366) return 29; else return 28; } unsigned int get_solar_total(unsigned int solar_year, unsigned char solar_month) { unsigned int total; unsigned int temp_num; total=0; for(temp_num=1900;temp_num for(temp_num=1;temp_num return total; } unsigned char solar_lunar(unsigned int kp_year,unsigned char kp_month,unsigned char kp_day) { unsigned int total_day=0; unsigned char run_yue_flag=0,run_yue=0,year_flag=0; if(kp_year<1900 || kp_year>2050 || kp_month>12 || kp_month==0 || (kp_year==1900 && kp_month==1) ) return 0; if(kp_day>day(kp_year,kp_month) || kp_day==0) return 0; total_day=get_solar_total( kp_year, kp_month)+kp_day-30; lunar_year=1900; while(total_day>385) { total_day-=get_lunar_year_total(lunar_year); lunar_year++; } if(total_day>get_lunar_year_total(lunar_year)) { total_day-=get_lunar_year_total(lunar_year); lunar_year++; } run_yue=get_leap_month(lunar_year); if(run_yue) run_yue_flag=1; else run_yue_flag=0; if(total_day==0) { lunar_day=get_lunar_month_total(lunar_year,12); lunar_month=12; } else { lunar_month=1; while(lunar_month<=12) { if( run_yue_flag==1 && lunar_month==(run_yue+1) ) { if(total_day>get_leap_month_day(lunar_year)) { total_day-=get_leap_month_day(lunar_year); } run_yue_flag=0; continue; } if( total_day> get_lunar_month_total(lunar_year,lunar_month ) ) { total_day=total_day-get_lunar_month_total(lunar_year,lunar_month); lunar_month++; } else { lunar_day=total_day; break; } } } }//以上代码来自互联网! main() { int solar_year; char solar_month; char solar_day; int time; int A,P,Q,B,D;//A为年份,D为月份 int e,f,g,h,i,j,M,N,E,F,Y,W,R,T,t,S,b,m; printf(" 测八字n"); printf("生辰八字或者说八字,其实是周易术语四柱的另一种说法。n"); printf("四柱是指人出生的时间、即年、月、日、时。n"); printf("在人用天干和地支各出一字相配合分别来表示年、月、日、时。n"); printf("如甲子年、丙申月、辛丑日、壬寅时等,包含了一个人出生时的天体运行的基本状态。n"); printf("每柱两字,四柱共八字,所以算命又称“测八字”。nn"); printf("依照天干、地支沂涵阴阳五行属性之相生、相克的关系,推测人的体咎祸福。n"); printf("一、(特别说明)时辰的输入方式:n"); printf("例如:n"); printf(" 1、出生时辰在(2:00~2:59)之间,则均以2计入即输入2。其他区间类同;n"); printf(" 2、若出生时辰在(0:00~0:59)之间,则输入24;n"); printf(" 3、默认输入时辰为24小时制。n"); printf("二、输入举例:n"); printf(" 1、生辰为1993年阳历4月8日早上6点15,则输入:1993/4/8/6n"); printf(" 2、生辰为1991年阳历8月16日下午16点59,则输入:1991/8/16/16n"); printf("nn"); printf("请输入您的出生年月日及时辰:"); scanf("%d/%d/%d/%d",&solar_year,&solar_month,&solar_day,&time); solar_lunar(solar_year,solar_month,solar_day); printf("您的农历生日为:%u年农历%u月%u日n",lunar_year,lunar_month,lunar_day); A=solar_year;//A为阳历年份, F=(int)solar_month;//F为阳历月份, E=(int)solar_day;//E为阳历日数, S=(int)time; R=(int)lunar_year;//R为农历年份, D=(int)lunar_month;//D为农历月份, for(P=R%10;P>10;R=R/10); for(Q=R%12;Q>12;R=R/12); printf("您的生辰八字为:"); switch(P) { case 4:printf("甲");break; case 5:printf("乙");break; case 6:printf("丙");break; case 7:printf("丁");break; case 8:printf("戊");break; case 9:printf("己");break; case 0:printf("庚");break; case 1:printf("辛");break; case 2:printf("壬");break; case 3:printf("癸");break; } switch(Q) { case 4:printf("子,");break; case 5:printf("丑,");break; case 6:printf("寅,");break; case 7:printf("卯,");break; case 8:printf("辰,");break; case 9:printf("巳,");break; case 10:printf("午,");break; case 11:printf("未,");break; case 0:printf("申,");break; case 1:printf("酉,");break; case 2:printf("戌,");break; case 3:printf("亥,");break; } if(P==4||P==9) B=1; if(P==5||P==0) B=2; if(P==6||P==1) B=3; if(P==7||P==2) B=4; if(P==8||P==3) B=5; b=F+1; switch(B) {case 1: switch(b) {case 3:printf("丙寅,");break; case 4:printf("丁卯,");break; case 5:printf("戊辰,");break; case 6:printf("己巳,");break; case 7:printf("庚午,");break; case 8:printf("辛未,");break; case 9:printf("壬申,");break; case 10:printf("癸酉,");break; case 11:printf("甲戌,");break; case 12:printf("乙亥,");break; case 1:printf("甲子,");break; case 2:printf("乙丑,");break; default:printf("您输入的月份有误!"); };break; case 2: switch(b) {case 3:printf("戊寅,");break; case 4:printf("己卯,");break; case 5:printf("庚辰,");break; case 6:printf("辛巳,");break; case 7:printf("壬午,");break; case 8:printf("癸未,");break; case 9:printf("甲申,");break; case 10:printf("乙酉,");break; case 11:printf("丙戌,");break; case 12:printf("丁亥,");break; case 1:printf("丙子,");break; case 2:printf("丁丑,");break; default:printf("您输入的月份有误!"); };break; case 3: switch(b) {case 3:printf("庚寅,");break; case 4:printf("辛卯,");break; case 5:printf("壬辰,");break; case 6:printf("癸巳,");break; case 7:printf("申午,");break; case 8:printf("乙未,");break; case 9:printf("丙申,");break; case 10:printf("丁酉,");break; case 11:printf("戊戌,");break; case 12:printf("己亥,");break; case 1:printf("戊子,");break; case 2:printf("己丑,");break; default:printf("您输入的月份有误!"); };break; case 4: switch(b) {case 3:printf("壬寅,");break; case 4:printf("癸卯,");break; case 5:printf("甲辰,");break; case 6:printf("乙巳,");break; case 7:printf("丙午,");break; case 8:printf("丁未,");break; case 9:printf("戊申,");break; case 10:printf("己酉,");break; case 11:printf("庚戌,");break; case 12:printf("辛亥,");break; case 1:printf("庚子,");break; case 2:printf("辛丑,");break; default:printf("您输入的月份有误!"); }break; case 5: switch(b) {case 3:printf("甲寅,");break; case 4:printf("乙卯,");break; case 5:printf("丙辰,");break; case 6:printf("丁巳,");break; case 7:printf("戊午,");break; case 8:printf("己未,");break; case 9:printf("庚申,");break; case 10:printf("辛酉,");break; case 11:printf("壬戌,");break; case 12:printf("癸亥,");break; case 1:printf("壬子,");break; case 2:printf("癸丑,");break; default:printf("您输入的月份有误!"); };break; } if(F==1) {F=13;A=A-1;} if(F==2) {F=14;A=A-1;} e=(int)(A/100); f=(int)(A/400); g=A-(int)(A/100)*100; h=(int)(g/4); i=(int)(3*(F+1)/5); M=4*e+f+5*g+h+i+E-3; if(D%2==0) j=0; else j=6; N=8*e+f+5*g+h+i+j+E+7; Y=M%10; W=N%12; switch(Y) {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; case 7:printf("庚");break; case 8:printf("辛");break; case 9:printf("壬");break; case 10:printf("癸");break; } switch(W) {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; case 7:printf("午,");break; case 8:printf("未,");break; case 9:printf("申,");break; case 10:printf("酉,");break; case 11:printf("戌,");break; case 12:printf("亥,");break; } if(Y==1||Y==6) T=1; if(Y==2||Y==7) T=2; if(Y==3||Y==8) T=3; if(Y==4||Y==9) T=4; if(Y==5||Y==10||Y==0) T=5; if(S==23||S==0||S==24) t=1; if(S==1||S==2) t=2; if(S==3||S==4) t=3; if(S==5||S==6) t=4; if(S==7||S==8) t=5; if(S==9||S==10) t=6; if(S==11||S==12) t=7; if(S==13||S==14) t=8; if(S==15||S==16) t=9; if(S==17||S==18) t=10; if(S==19||S==20) t=11; if(S==21||S==22) t=12; switch(T) {case 1: switch(t) {case 1:printf("甲子");break; case 2:printf("乙丑");break; case 3:printf("丙寅");break; case 4:printf("丁卯");break; case 5:printf("戊辰");break; case 6:printf("己巳");break; case 7:printf("庚午");break; case 8:printf("辛未");break; case 9:printf("壬申");break; case 10:printf("癸酉");break; case 11:printf("甲戌");break; case 12:printf("乙亥");break; };break; case 2: switch(t) {case 1:printf("丙子");break; case 2:printf("丁丑");break; case 3:printf("戊寅");break; case 4:printf("己卯");break; case 5:printf("庚辰");break; case 6:printf("辛巳");break; case 7:printf("壬午");break; case 8:printf("癸未");break; case 9:printf("甲申");break; case 10:printf("乙酉");break; case 11:printf("丙戌");break; case 12:printf("丁亥");break; };break; case 3: switch(t) {case 1:printf("戊子");break; case 2:printf("己丑");break; case 3:printf("庚寅");break; case 4:printf("辛卯");break; case 5:printf("壬辰");break; case 6:printf("癸巳");break; case 7:printf("甲午");break; case 8:printf("乙未");break; case 9:printf("丙申");break; case 10:printf("丁酉");break; case 11:printf("戊戌");break; case 12:printf("己亥");break; };break; case 4: switch(t) {case 1:printf("庚子");break; case 2:printf("辛丑");break; case 3:printf("壬寅");break; case 4:printf("癸卯");break; case 5:printf("甲辰");break; case 6:printf("乙巳");break; case 7:printf("丙午");break; case 8:printf("丁未");break; case 9:printf("戊申");break; case 10:printf("己酉");break; case 11:printf("庚戌");break; case 12:printf("辛亥");break; };break; case 5: switch(t) {case 1:printf("壬子");break; case 2:printf("癸丑");break; case 3:printf("甲寅");break; case 4:printf("乙卯");break; case 5:printf("丙辰");break; case 6:printf("丁巳");break; case 7:printf("戊午");break; case 8:printf("己未");break; case 9:printf("庚申");break; case 10:printf("辛酉");break; case 11:printf("壬戌");break; case 12:printf("癸亥");break; };break; } printf("n您的五行纳音为:"); m=P*10+Q; switch(m) { case 44:printf("海中金");break; case 55:printf("海中金");break; case 66:printf("炉中火");break; case 77:printf("炉中火");break; case 88:printf("大林木");break; case 99:printf("大林木");break; case 10:printf("路旁土");break; case 21:printf("路旁土");break; case 20:printf("剑锋金");break; case 31:printf("剑锋金");break; case 42:printf("山头火");break; case 53:printf("山头火");break; case 64:printf("洞下水");break; case 75:printf("洞下水");break; case 86:printf("城墙土");break; case 97:printf("城墙土");break; case 8:printf("白腊金");break; case 19:printf("白腊金");break; case 30:printf("杨柳木");break; case 41:printf("杨柳木");break; case 40:printf("泉中水");break; case 51:printf("泉中水");break; case 62:printf("屋上土");break; case 73:printf("屋上土");break; case 84:printf("霹雷火");break; case 95:printf("霹雷火");break; case 6:printf("松柏木");break; case 17:printf("松柏木");break; case 28:printf("常流水");break; case 39:printf("常流水");break; case 50:printf("沙中金");break; case 61:printf("沙中金");break; case 60:printf("山下火");break; case 71:printf("山下火");break; case 82:printf("平地木");break; case 93:printf("平地木");break; case 4:printf("壁上土");break; case 15:printf("壁上土");break; case 26:printf("金箔金");break; case 37:printf("金箔金");break; case 48:printf("佛灯火");break; case 59:printf("佛灯火");break; case 70:printf("天河水");break; case 81:printf("天河水");break; case 80:printf("大驿土");break; case 91:printf("大驿土");break; case 2:printf("钗钏金");break; case 13:printf("钗钏金");break; case 24:printf("桑松木");break; case 35:printf("桑松木");break; case 46:printf("大溪水");break; case 57:printf("大溪水");break; case 68:printf("沙中土");break; case 79:printf("沙中土");break; case 90:printf("天上火");break; case 101:printf("天上火");break; case 0:printf("石榴木");break; case 11:printf("石榴木");break; case 22:printf("大海水");break; case 33:printf("大海水");break; } printf("n"); system("pause"); } |
|
相关推荐 |
|
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-28 13:09 , Processed in 0.520471 second(s), Total 47, Slave 34 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号