Democratic Underground Latest Greatest Lobby Journals Search Options Help Login
Google

Now, here's a program for calculating the date of Easter.

Printer-friendly format Printer-friendly format
Printer-friendly format Email this thread to a friend
Printer-friendly format Bookmark this thread
This topic is archived.
Home » Discuss » The DU Lounge Donate to DU
 
Commie Pinko Dirtbag Donating Member (1000+ posts) Send PM | Profile | Ignore Fri Jan-26-07 02:56 PM
Original message
Now, here's a program for calculating the date of Easter.
Edited on Fri Jan-26-07 02:57 PM by Commie Pinko Dirtbag
Adapted the mechanism showed here: http://en.wikipedia.org/wiki/Computus#Meeus.2FJones.2FButcher_Gregorian_algorithm

Save the text below as easter.c and, under Linux or Mac OS, compile like this: "gcc -DSTANDALONE -Wall -o easter easter.c"

It should also compile as a console program under Visual C++. I suppose.

Programmer types can use it as a library, by not defining STANDALONE.

"easter", on its own, prints this year's Easter. For other years, use "easter 2009", "easter 1993" etc.

#include <time.h>

#ifdef STANDALONE
#include <stdio.h>
#include <stdlib.h>
#endif

void easter(int year, int *month, int *day)
{
int a, b, c, d, e, f, g, h, i, k, l, m;

a = year % 19;
b = year / 100;
c = year % 100;
d = b / 4;
e = b % 4;
f = (b + 8) / 25;
g = (b - f + 1) / 3;
h = (19 * a + b - d - g + 15) % 30;
i = c / 4;
k = c % 4;
l = (32 + 2 * e + 2 * i - h - k) % 7;
m = (a + 11 * h + 22 * l) / 451;
*month = (h + l - 7 * m + 114) / 31;
*day = ((h + l - 7 * m + 114) % 31) + 1;
}

#ifdef STANDALONE
int main (int argc, char **argv)
{
int myyear, mymonth, myday;
time_t now;
struct tm localnow;

if (argc < 2)
{
time(&now);
localtime_r(&now, &localnow);
myyear = localnow.tm_year + 1900;
}
else
myyear = atoi(*(argv + 1));

easter(myyear, &mymonth, &myday);
printf("%d/%d/%d\n", myyear, mymonth, myday);

return 0;
}
#endif


EDIT: the above is in the public domain.
Printer Friendly | Permalink |  | Top
yvr girl Donating Member (1000+ posts) Send PM | Profile | Ignore Fri Jan-26-07 03:07 PM
Response to Original message
1. way back in the stone ages, I made a perpetual calendar
for my programming class. Easter was the trickiest part.
Printer Friendly | Permalink |  | Top
 
DU AdBot (1000+ posts) Click to send private message to this author Click to view 
this author's profile Click to add 
this author to your buddy list Click to add 
this author to your Ignore list Thu Dec 26th 2024, 01:59 PM
Response to Original message
Advertisements [?]
 Top

Home » Discuss » The DU Lounge Donate to DU

Powered by DCForum+ Version 1.1 Copyright 1997-2002 DCScripts.com
Software has been extensively modified by the DU administrators


Important Notices: By participating on this discussion board, visitors agree to abide by the rules outlined on our Rules page. Messages posted on the Democratic Underground Discussion Forums are the opinions of the individuals who post them, and do not necessarily represent the opinions of Democratic Underground, LLC.

Home  |  Discussion Forums  |  Journals |  Store  |  Donate

About DU  |  Contact Us  |  Privacy Policy

Got a message for Democratic Underground? Click here to send us a message.

© 2001 - 2011 Democratic Underground, LLC