A Conversation for Calculating the Date of Easter
C-ified version
sinclair44 Started conversation May 3, 2003
This is standard, portable C that will use the algorithim detailed above.
*****
#include
void calcEaster(int year, int *month, int *day);
int main (int argc, const char * argv[])
{
int year, month, day;
printf("Calculates the month and day of easter on given year.\n");
printf("Enter a year between 1700 and 2299: ");
fflush(stdout);
scanf("%i", &year);
if (year < 1700 || year > 2299)
printf("WARNING: Following results may be off; year out of range that algorithm has been tested with.\n");
calcEaster(year, &month, &day);
printf("Month: %i\nDay: %i\n", month, day);
return 0;
}
void calcEaster(int year, int *month, int *day)
{
// Algorithm from h2g2: http://www.bbc.co.uk/dna/h2g2/A653267
int a, b, c, d, e, f, g, h, i, j, k, m, n;
printf("Algorithm from the h2g2: http://www.bbc.co.uk/dna/h2g2/A653267\n");
a = year % 19;
b = year / 100;
c = year % 100;
d = b / 4;
e = b % 4;
f = c / 4;
g = c % 4;
h = (b + 8) / 25;
i = (b - h + 1)/ 3;
j = (19 * a + b - d - i + 15) % 30;
k = (32 + 2 * e + 2 * f - j - g) % 7;
m = (a + 11 * j + 22 * k) / 451;
n = j + k - 7 * m + 114;
*month = n / 31;
*day = (n % 31) + 1;
}
Key: Complain about this post
C-ified version
More Conversations for Calculating the Date of Easter
Write an Entry
"The Hitchhiker's Guide to the Galaxy is a wholly remarkable book. It has been compiled and recompiled many times and under many different editorships. It contains contributions from countless numbers of travellers and researchers."