Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
//
//INCLUDE files for :EASTER.C - Determin
// e the date of Easter for any given year
//**************************************
//
/* +++Date last modified: 05-Jul-1997 */
/*
** Header for SNIPPETS date & time function, excluding scalar dates
*/
#ifndef DATETIME__H
#define DATETIME__H
#include "sniptype.h"
/*
** Julian day number functions from JDN_L.C
*/
long ymd_to_jdnl(int y, int m, int d, int julian);
void jdnl_to_ymd(long jdn, int *yy, int *mm, int *dd, int julian);
/*
** Add times from ADDTIME.C
*/
int add_time(unsigned basehrs, unsigned basemins, unsigned basesecs,
int spanhrs, int spanmins, int spansecs,
unsigned *hrs, unsigned *mins, unsigned *secs, int *days);
/*
** Determine the date of Easter for any given year
*/
void easter(int year, int *easter_month, int *easter_day);
/*
** Moon phase from MOON_AGE.C
*/
int moon_age(int month, int day, int year);
/*
** Date parser from PARSDATE.C
*/
typedef enum {USA, ISO, EUROPE} Syntax_T;
Boolean_T parse_date(const char *str, unsigned *year, unsigned *month,
unsigned *day, Syntax_T syntax);
/*
** Time parser from PARSTIME.C
*/
Boolean_T parse_time(const char *str, unsigned *hours, unsigned *mins,
unsigned *secs);
#endif /* DATETIME__H */
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
Terms of Agreement:
By using this code, you agree to the following terms...
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for langauges that allow it) freely and with no charge.
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame.
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
//
/* +++Date last modified: 05-Jul-1997 */
/*
** EASTER.C - Determine the date of Easter for any given year
**
** public domain by Ed Bernal
*/
#include
#include "datetime.h"
void easter(int year,int *easter_month, int *easter_day)
{
int a,b,c,e,g,h,i,k,u,x,z;
div_t f;
/*
** Gauss' famous algorithm (I don't know how or why it works,
** so there's no commenting)
*/
a = year % 19;
f = div(year,100);
b = f.quot;
c = f.rem;
f = div(b,4);
z = f.quot;
e = f.rem;
f = div((8*b + 13),25);
g = f.quot;
f = div((19*a + b - z - g + 15),30);
h = f.rem;
f = div((a + 11*h),319);
u = f.quot;
f = div(c,4);
i = f.quot;
k = f.rem;
f = div((2*e + 2*i - k - h + u + 32),7);
x = f.rem;
f = div((h-u+x+90),25);
*easter_month = f.quot;
f = div((h-u+x + *easter_month +19),32);
*easter_day = f.rem;
}
#ifdef TEST
#include
main(int argc, char *argv[])
{
int yr, mo, dy;
while (--argc)
{
yr = atoi(*++argv);
if (100 > yr)
yr += 1900;
easter(yr, &mo, &dy);
printf("Easter in %d on %d/%d\n", yr, mo, dy);
}
return 0;
}
#endif /* TEST */