Determine Date of Easter Atom Feed 0

In Brief A completely opaque way to determine the date of easter for any year, using Gauss's algorithm.... more
# 's
 1/*
2** EASTER.C - Determine the date of Easter for any given year
3**
4** public domain by Ed Bernal
5*/
6
7#include <stdlib.h>
8#include "datetime.h"
9
10
11void easter(int year,int *easter_month, int *easter_day)
12{
13 int a,b,c,e,g,h,i,k,u,x,z;
14 div_t f;
15
16 /*
17 ** Gauss' famous algorithm (I don't know how or why it works,
18 ** so there's no commenting)
19 */
20
21 a = year % 19;
22 f = div(year,100);
23 b = f.quot;
24 c = f.rem;
25 f = div(b,4);
26 z = f.quot;
27 e = f.rem;
28 f = div((8*b + 13),25);
29 g = f.quot;
30 f = div((19*a + b - z - g + 15),30);
31 h = f.rem;
32 f = div((a + 11*h),319);
33 u = f.quot;
34 f = div(c,4);
35 i = f.quot;
36 k = f.rem;
37 f = div((2*e + 2*i - k - h + u + 32),7);
38 x = f.rem;
39 f = div((h-u+x+90),25);
40 *easter_month = f.quot;
41 f = div((h-u+x + *easter_month +19),32);
42 *easter_day = f.rem;
43}
44
45#ifdef TEST
46
47#include <stdio.h>
48
49main(int argc, char *argv[])
50{
51 int yr, mo, dy;
52
53 while (--argc)
54 {
55 yr = atoi(*++argv);
56 if (100 > yr)
57 yr += 1900;
58 easter(yr, &mo, &dy);
59 printf("Easter in %d on %d/%d\n", yr, mo, dy);
60 }
61 return 0;
62}
63
64#endif /* TEST */

A completely opaque way to determine the date of easter for any year, using Gauss's algorithm.

Define TEST for the compiler to get a test main() function.

Incidentally, Easter officially falls on the first Sunday after the 14th day of the lunar month that starts (has a full moon) after March 21st. Or something.