#include static char * monthName[12] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; static char * dayName[7] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; /* Our base year is 1900. Since 1 January 1900 was a Monday, we get the ** following keys for the months. */ static int mkeys[12] = { 1, 4, 4, 0, 2, 5, 0, 3, 6, 1, 4, 6 }; /* This function converts month, date, and year to the day of the week, ** returning an integer between 0 and 6, inclusive, with 0 indicating Sunday. ** This function should work for any year from 1901 to 2099. */ static int DayOfWeek( int month, int date, int year ) { int day; day = ( year - 1900 ) + ( year - 1900 ) / 4 + mkeys[month] + date - 1; /* The above counts the leap day even if it occurs later in the year */ if(( year > 1900 ) && ( year % 4 == 0 ) && ( month < 2 ) ) day--; day %= 7; return day; } void main( int argc, char *argv[] ) { int month, date, year, day; sscanf( argv[1], "%d", &month ); month--; sscanf( argv[2], "%d", &date ); sscanf( argv[3], "%d", &year ); day = DayOfWeek( month, date, year ); printf( "%d %s %d is a %s\n", date, monthName[month], year, dayName[day] ); return; }