Gustavo said:
It is possible to caclulate every year's easter using simple
mathematical operations. Here is a code that does the trick:
http://www.brlivre.org/c/easter.c
I found the math scheme in an american scientific issue, march
2001. The article about the calendars is very interesting.
// Calculating Easter
#include <stdio.h>
#include <stdlib.h>
static const
char *month_array[] = {
"January", "February", "March",
"April", "May", "June",
"July", "August", "September",
"October", "November", "December" };
typedef struct Date {
int year;
int month;
int day;
} Date;
inline static
Date Date_create(int year, int month, int day) {
Date d;
d.year = year;
d.month = month;
d.day = day;
return d;
}
inline static
void Date_destroy(const Date* p) {
}
Date easter(int x) {
int a = x%19;
int b = x/100;
int c = x%100;
int h = (19*a + b - (b/4) - (8*b + 13)/25 + 15)%30;
int m = (a + 11*h)/319;
int l = (2*(b%4) + 2*(c/4) - c%4 - h + m + 32)%7;
int n = (h - m + l + 90)/25;
int p = (h - m + l + n + 19)%32;
return Date_create(x, n - 1, p);
}
int main(int argc, char *argv[]) {
int year; /* year to determine easter */
if (argc == 1) {
printf("Year: ");
scanf("%d", &year);
}
else
year = atoi(argv[1]);
Date d = easter(year);
printf("Easter %d is %s %d.\n",
d.year, month_array[d.month], d.day);
Date_destroy(&d);
return EXIT_SUCCESS;
}
> gcc -Wall -std=c99 -pedantic -o easter easter.c
> ./easter 2004
Easter 2004 is April 11.