Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!texbell!bigtex!pmafire!rickf From: rickf@pmafire.UUCP (rick furniss) Newsgroups: comp.lang.c Subject: Re: Computing Day of the Week Keywords: given month and day Message-ID: <890@pmafire.UUCP> Date: 6 Dec 89 16:07:32 GMT References: <1894@ntmtka.mn.org> Reply-To: rickf@pmafire.UUCP (Rick Furniss) Distribution: usa Organization: WINCO, INEL, Idaho Lines: 36 #include main (argc,argv) char **argv; int argc; { int result; int year=atoi(argv[1]), month=atoi(argv[2]), day=atoi(argv[3]); if (argc != 4 ) { fprintf(stderr,"Usage: %s YY MM DD\n",argv[0]); exit(1); } result=day_of_week(year,month,day); fprintf(stdout,"day # %i\n",result); exit(0); } /* Find and return day of week (0-6) */ int day_of_week(year,month,day) int year,month,day; { static int offsets[13] = { 0,0,3,3,6,1,4,6,2,5,7,3,5 }; int dw; dw=6+year+((year+3)/4)+offsets[month]+day; if( ((year%4) ==0) && (month > 2)) dw++; if( (year==0) && (month < 3)) dw++; dw=(dw%7); return(dw); } Standard disclaimer ******* Rick Furniss