int weekDay( int day, int month, int year ){ // Returns the day of the week for the given date, assumed valid and // in the Gregorian calendar. The returned value is: 0 for Sunday, // 1 for Monday, ..., 6 for Saturday; or, if the preprocessor symbol // MONDAY_IS_0 is defined: 0 for Monday, 1 for Tuesday, ..., 6 for // Sunday. int result; if (month < 3) { month += 12; --year; } result = day + (13 * month - 27)/5 + year + year/4 - year/100 + year/400; #ifdef MONDAY_IS_0 result += 6; #endif // MONDAY_IS_0 return (result % 7); }