c语言农历程序,c52单片机c语言编程怎样实现阴历查询

2023-12-25 00:10

本文主要是介绍c语言农历程序,c52单片机c语言编程怎样实现阴历查询,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

fa0b36a856ae8af3cc19bfa8ffa8d10f.png

原创 农历转阴历 c语言收藏

/*

2008.5.3-2008.5.8

呵呵!最近没什么是,打算自己做个万年历,下面是我在网上下的一个程序,

void  solar_lunar(unsigned int kp_year,unsigned char kp_month,unsigned char kp_day)

这个函数是我写的,测试了一下基本上没出什么问题

在 WIN-TC运行过的。

*/

#include

/*

阳历1900.1.1

在阳历为1900.1.31  时阴历为1900.1.1 即1900年正月初一

*/

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,  //1980

0x04af5,0x04970,0x064b0,0x074a3,0x0ea50,0x06b58,0x055c0,0x0ab60,0x096d5,0x092e0,

0x0c960,0x0d954,0x0d4a0,0x0da50,0x07552,0x056a0,0x0abb7,0x025d0,0x092d0,0x0cab5,  //2004 07552

0x0a950,0x0b4a0,0x0baa4,0x0ad50,0x055d9,0x04ba0,0x0a5b0,0x15176,0x052b0,0x0a930,

0x07954,0x06aa0,0x0ad50,0x05b52,0x04b60,0x0a6e6,0x0a4e0,0x0d260,0x0ea65,0x0d530, //2028

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)  //若存在闰月,返回闰月的天数,30?29

{

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) //确定农历当月天数,30?29

{

return( (lunar_info[lunar_year-1900] & (0x10000>>lunar_month) ) ? 30:29 );

}

//---------------------------------------------

unsigned int get_lunar_year_total(unsigned int lunar_year) // 农历当年总天数,354?355 384 383

{

/*sum=12*29 */   //12个月 29天一月

unsigned int sum=348;

unsigned int i;

for(i=0x8000;i>0x8; i>>=1)

sum+=(lunar_info[lunar_year-1900]&i)?1:0;  //把大月的1加进去

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;

}

//-------------------------------------------

//计算1900.1.1 到  输入年月的天数

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

total+=leap(temp_num);

for(temp_num=1;temp_num

total+=day(solar_year,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;/*记录农历1900.1.1日到今天相隔的天数 */

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; /* 阳历从1900.1.31(农历1900.1.1)到今天的总天数(减30 实际少了一天)。 */

lunar_year=1900;

while(total_day>385) //385大于一年  留出一年多的时间用于条件计算

{

total_day-=get_lunar_year_total(lunar_year); //

lunar_year++;

}

if(total_day>get_lunar_year_total(lunar_year))  //排除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; //有闰月则一年为13个月

else

run_yue_flag=0;  //没闰月则一年为12个月

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);  //该年闰月天数

}

//lunar_month--;

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;

}

}

}

}

//--------------------------------------------

void main(void)

{

while(1)

{

printf("\nplease input  Y M D:");

scanf("%d",&solar_year);

scanf("%d",&solar_month);

scanf("%d",&solar_day);

solar_lunar(solar_year,solar_month,solar_day);

printf("\nlunar_year:%u",lunar_year);

printf("\nlunar_month:%u",lunar_month);

printf("\nlunar_day:%u",lunar_day);

getch();

}

◆◆

评论读取中....

请登录后再发表评论!

◆◆

修改失败,请稍后尝试

这篇关于c语言农历程序,c52单片机c语言编程怎样实现阴历查询的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/533617

相关文章

Qt实现对Word网页的读取功能

《Qt实现对Word网页的读取功能》文章介绍了几种在Qt中实现Word文档(.docx/.doc)读写功能的方法,包括基于QAxObject的COM接口调用、DOCX模板替换及跨平台解决方案,重点讨论... 目录1. 核心实现方式2. 基于QAxObject的COM接口调用(Windows专用)2.1 环境

MySQL查看表的历史SQL的几种实现方法

《MySQL查看表的历史SQL的几种实现方法》:本文主要介绍多种查看MySQL表历史SQL的方法,包括通用查询日志、慢查询日志、performance_schema、binlog、第三方工具等,并... 目录mysql 查看某张表的历史SQL1.查看MySQL通用查询日志(需提前开启)2.查看慢查询日志3.

Java实现字符串大小写转换的常用方法

《Java实现字符串大小写转换的常用方法》在Java中,字符串大小写转换是文本处理的核心操作之一,Java提供了多种灵活的方式来实现大小写转换,适用于不同场景和需求,本文将全面解析大小写转换的各种方法... 目录前言核心转换方法1.String类的基础方法2. 考虑区域设置的转换3. 字符级别的转换高级转换

使用Python实现局域网远程监控电脑屏幕的方法

《使用Python实现局域网远程监控电脑屏幕的方法》文章介绍了两种使用Python在局域网内实现远程监控电脑屏幕的方法,方法一使用mss和socket,方法二使用PyAutoGUI和Flask,每种方... 目录方法一:使用mss和socket实现屏幕共享服务端(被监控端)客户端(监控端)方法二:使用PyA

MyBatis-Plus逻辑删除实现过程

《MyBatis-Plus逻辑删除实现过程》本文介绍了MyBatis-Plus如何实现逻辑删除功能,包括自动填充字段、配置与实现步骤、常见应用场景,并展示了如何使用remove方法进行逻辑删除,逻辑删... 目录1. 逻辑删除的必要性编程1.1 逻辑删除的定义1.2 逻辑删php除的优点1.3 适用场景2.

C#借助Spire.XLS for .NET实现在Excel中添加文档属性

《C#借助Spire.XLSfor.NET实现在Excel中添加文档属性》在日常的数据处理和项目管理中,Excel文档扮演着举足轻重的角色,本文将深入探讨如何在C#中借助强大的第三方库Spire.... 目录为什么需要程序化添加Excel文档属性使用Spire.XLS for .NET库实现文档属性管理Sp

Python+FFmpeg实现视频自动化处理的完整指南

《Python+FFmpeg实现视频自动化处理的完整指南》本文总结了一套在Python中使用subprocess.run调用FFmpeg进行视频自动化处理的解决方案,涵盖了跨平台硬件加速、中间素材处理... 目录一、 跨平台硬件加速:统一接口设计1. 核心映射逻辑2. python 实现代码二、 中间素材处

MySQL中between and的基本用法、范围查询示例详解

《MySQL中betweenand的基本用法、范围查询示例详解》BETWEENAND操作符在MySQL中用于选择在两个值之间的数据,包括边界值,它支持数值和日期类型,示例展示了如何使用BETWEEN... 目录一、between and语法二、使用示例2.1、betwphpeen and数值查询2.2、be

Java数组动态扩容的实现示例

《Java数组动态扩容的实现示例》本文主要介绍了Java数组动态扩容的实现示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧... 目录1 问题2 方法3 结语1 问题实现动态的给数组添加元素效果,实现对数组扩容,原始数组使用静态分配

Python实现快速扫描目标主机的开放端口和服务

《Python实现快速扫描目标主机的开放端口和服务》这篇文章主要为大家详细介绍了如何使用Python编写一个功能强大的端口扫描器脚本,实现快速扫描目标主机的开放端口和服务,感兴趣的小伙伴可以了解下... 目录功能介绍场景应用1. 网络安全审计2. 系统管理维护3. 网络故障排查4. 合规性检查报错处理1.