//------------------------------------------------------------------- // knuth.cpp // // This program implements the Date-of-Easter Algorithm in a // high-level programming language, showing the intermediate // results for each step in the calculation. // // Reference: Donald Knuth, The Art of Computer Programming, // Volume 1: Fundamental Algorithms (2nd Ed., 1973), p155-6. // // programmer: ALLAN CRUSE // date begun: 28 SEP 2003 //------------------------------------------------------------------- #include // for printf() #include // for atoi(), exit() int main( int argc, char **argv ) { if ( argc == 1 ) exit(1); int year = atoi( argv[ 1 ] ); printf( "\nyear=%d \n", year ); if ( year < 1582 ) exit(2); int golden = ( year % 19 ) + 1; printf( "golden=%d \n", golden ); int century = ( year / 100 ) + 1; printf( "century=%d \n", century ); int x = ( 3 * century / 4 ) - 12; int z = ( 8 * century / 25 ) - 5; printf( "x=%d z=%d \n", x, z ); int day = ( 5 * year / 4 ) - x - 10; printf( "day=%d \n", day ); int epact = ( 11 * golden + 20 + z - x ) % 30; if ( (( epact == 25 )&&( golden > 11 ))||( epact == 24 ) ) ++epact; printf( "epact=%d \n", epact ); int moon = 44 - epact; if ( moon < 21 ) moon += 30; printf( "moon=%d \n", moon ); int n = ( moon + 7 ) - ( ( day + moon ) % 7 ); printf( "n=%d \n", n ); if ( n > 31 ) printf( "%d April %d \n\n", n-31, year ); else printf( "%d March %d \n\n", n, year ); }