Over a million developers have joined DZone.

Easter Date - C

·
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;
  }
}
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}