DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Easter Date - C

05.09.2007
| 3097 views |
  • submit to reddit
        Easter_c computes the easter date for year Y. It uses the standard (as used by most western churches) algorithm developed by the Napolitan astronomer Aloysius Lilius and the Jesuit mathematician Christopher Clavius. It works for any year after 1582.

typedef struct {
  unsigned char d;
  unsigned char m;
} Date;

void easter_c(unsigned short Y, Date *d) {
  int G = (Y % 19) + 1;
  int C = (int)(Y / 100) + 1;
  int X = 3 * C / 4 - 12;
  int Z = (8 * C + 5) / 25 - 5;
  int D = 5 * Y / 4 - X - 10;
  int E = (11 * G + 20 + Z - X) % 30;
  if (((E == 25) && (G > 11)) || (E == 24))
    ++E;
  int N = 44 - E;
  if (N < 21)
    N += 30;
  N = N + 7 - ((D + N) % 7);

  if (N > 31) {
    d->d = N - 31;
    d->m = 4;
  } else {
    d->d = N;
    d->m = 3;
  }
}