Skip to content

Fun feature: Easter and Leap year #17

@chlordk

Description

@chlordk

Looks great. Everything is almost here only easter is missing.

Easter can be a little tricky. Here is a simple example in C.

/* Source: https://www.rmg.co.uk/stories/topics/when-easter */

#include <stdio.h>

void easter(int y, int *m, int *d) {

*d = 225 - 11 * (y % 19);

while (*d > 50)
	*d -= 30;

if (*d > 48)
	--*d;

*d = *d + 7 - (y + y/4 + *d + 1) % 7;

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

return 0;
}

int main( void ) {

int year, day, month;

for (year=1998; year<2100; year++) { // algorithm does not work after 2099
	easter(year,&month,&day);
	printf("%d-%02d-%02d\n", year, month, day);
}

return 0;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions