C言语阴阳历算法-C / C++-优质IT资源分享社区

admin
管理员
管理员
  • UID1
  • 粉丝26
  • 关注4
  • 发帖数581
  • 社区居民
  • 忠实会员
  • 原创写手
阅读:131回复:0

  C言语阴阳历算法

楼主#
更多 发布于:2016-05-22 14:58

程序为:

/*

prototype: int calconv( struct convdate * );

struct convdate

{

int source; ==0 则输入日期为西历, !=0 则输入为阴历

int solaryear; 输出或输入之西历年份

int solarmonth; 西历月

int solardate; 西历日

int lunaryear; 输出或输入之阴历年份

int lunarmonth; 阴历月

int lunardate; 阴历日

int weekday; 该日为星期几 ( 0==周日, 1==星期一, ... )

int kan; 该日天干 ( 0==甲, 1==乙, ..., 9==癸 )

int chih; 该日地支 ( 0==子, 1==丑, ..., 11==亥 )

};

呼叫时须设定 souce 的值, 若为 0 则为西历转阴历, 否则为阴历转西历. 然後视

输入为西历或阴向来设定西历或阴历的年月日. 变换後的年月日会填入构造中( 农

历或西历 ), 以及该日为星期几, 天干地支.

若函式的返回值为 0 表明没有过错, 1 为输入之年份过错, 2 为输入之月份过错,

3 为输入之日期过错.

输入之西历年须在 1937 - 2031 间

输入之阴历年须在 1936 - 2030 间

若须扩大, 则增加 lunarcal[]

*/

#define firstyear 1936 /* the first year in

lunarcal[] */

struct convdate

{

int source;

int solaryear;

int solarmonth;

int solardate;

int lunaryear;

int lunarmonth;

int lunardate;

int weekday;

int kan;

int chih;

};

struct taglunarcal

{

int basedays; /* 到西历 1 月 1 日到阴历正月初一的累积日数 */

int intercalation; /* 闰月月份. 0==此年没有闰月 */

int baseweekday; /* 此年西历 1 月 1 日为星期几再减 1 */

int basekanchih; /* 此年西历 1 月 1 日之干支序号减 1 */

int monthdays; /* 此阴历年每月之巨细, 0==小月(29日),

1==大月(30日)*/

};

struct taglunarcal lunarcal[] = {

{ 23, 3, 2, 17, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1,

1, 0 }, /* 1936 */

{ 41, 0, 4, 23, 1, 0, 0, 1, 0, 0, 1, 0, 1, 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0, 0, 1, 1,

0, 1 },

{ 25, 5, 5, 20, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1,

1, 0 }, /* 2028 */

{ 43, 0, 0, 26, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1,

0, 1 },

{ 32, 0, 1, 31, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1,

0, 0 },

{ 22, 3, 2, 36, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0,

1, 0 } };

#define lastyear

(firstyear+sizeof(lunarcal)/sizeof(struct taglunarcal)-1)

优质IT资源分享社区为你提供此文。

本站有大量优质C、C++教程视频,资料等资源,包含C,C++基础教程,高级进阶教程等等,教程视频资源涵盖传智播客,极客学院,达内,北大青鸟,猎豹网校等等IT职业培训机构的培训教学视频,价值巨大。欢迎点击下方链接查看。

C、C++教程视频

优质IT资源分享社区(www.itziyuan.top)
一个免费,自由,开放,共享,平等,互助的优质IT资源分享网站。
专注免费分享各大IT培训机构最新培训教学视频,为你的IT学习助力!

!!!回帖受限制请看点击这里!!!
!!!资源失效请在此版块发帖说明!!!

[PS:按 CTRL+D收藏本站网址~]

——“优质IT资源分享社区”管理员专用签名~

本版相似帖子

游客