Created
September 9, 2011 17:48
-
-
Save mjf/1206860 to your computer and use it in GitHub Desktop.
Year - normal, leap or calendar change 1752 year?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Year - normal, leap or calendar change 1752 year? | |
* Copyright (C) 2011 Matous J. Fialka, <http://mjf.cz/> | |
* Released under the terms of The MIT License | |
* | |
* Install as follows: | |
* | |
* $ cc -pedantic -ansi -pedantic-errors -Wall -Werror year.c -o year | |
* $ su -c 'cp year /usr/local/bin' | |
*/ | |
#include <stdlib.h> | |
#include <stdio.h> | |
int | |
january1(const int y) | |
{ | |
int d = y + 4 + (y + 3) / 4; | |
if(y > 1800) | |
d -= (y - 1701) / 100, d += (y - 1601) / 400; | |
if(y > 1752) | |
d += 3; | |
return d % 7; | |
} | |
int | |
main(int argc, char *argv[]) | |
{ | |
int y = 0; | |
if(argc < 2) { | |
fprintf(stderr, "Usage: year [year ...]\n"); | |
return 1; | |
} | |
while(*++argv) { | |
y = atoi(*argv); | |
printf("%d is ", y); | |
switch ((january1(y + 1) + 7 - january1(y)) % 7) { | |
case 1: | |
printf("normal"); | |
break; | |
case 2: | |
printf("leap"); | |
break; | |
default: | |
printf("calendar change"); | |
break; | |
} | |
printf(" year\n"); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example usage may be as follows:
Enjoy!