Created
September 9, 2011 22:38
-
-
Save mjf/1207506 to your computer and use it in GitHub Desktop.
Easter - calculate Easter Sunday (Gregorian calender)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example usage may be as follows:
Enjoy!