Skip to content

Instantly share code, notes, and snippets.

@mjf
Created September 9, 2011 22:38
Show Gist options
  • Save mjf/1207506 to your computer and use it in GitHub Desktop.
Save mjf/1207506 to your computer and use it in GitHub Desktop.
Easter - calculate Easter Sunday (Gregorian calender)
/**
* Easter - calculate Easter Sunday (Gregorian calender)
* Copyright (C) 2011 Matous J. Fialka, <http://mjf.cz/>
* Released under the terms of The MIT License
*
* $ cc -pedantic -ansi -pedantic-errors -Wall -Werror easter.c -o easter
* $ su -c 'cp easter /usr/local/bin'
*/
#include <stdlib.h>
#include <stdio.h>
const char *s[12] = {
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
};
int
main(int argc, char *argv[])
{
int y, g, c, h, i, j, l, m, d;
if(argc < 2) {
fprintf(stderr, "Usage: easter [year ...]\n");
return 1;
}
while(*++argv) {
y = atoi(*argv);
g = y % 19;
c = y / 100;
h = (c - c / 4 - (8 * c + 13) / 25 + 19 * g + 15) % 30;
i = h - (h / 28) * (1 - (29 / (h + 1)) * ((21 - g) / 11));
j = (y + y / 4 + i + 2 - c + c / 4) % 7;
l = i - j;
m = 3 + (l + 40) / 44;
d = l + 28 - 31 * (m / 4);
printf("Sunday, %s %d, %d\n", s[m - 1], d, y);
}
return 0;
}
@mjf
Copy link
Author

mjf commented Sep 9, 2011

Example usage may be as follows:

$ easter 2010 2011 2012
Sunday, April 4, 2010
Sunday, April 24, 2011
Sunday, April 8, 2012

Enjoy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment