Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   given month, day, year, returns day of week, eg. Monday = 0 etc. (http://www.go4expert.com/forums/month-day-year-returns-day-week-eg-t25518/)

abhi150783 13Apr2011 16:18

given month, day, year, returns day of week, eg. Monday = 0 etc.
 
Is there any error or bug or loop in this piece of code??

//given month, day, year, returns day of week, eg. Monday = 0 etc.
int WeekDay(int month, int day, int year)
{
int ix, tx, vx;

switch (month)
{
case 2 :
case 6 : vx = 0; break;
case 8 : vx = 4; break;
case 10: vx = 8; break;
case 9 :
case 12: vx = 12; break;
case 3 :
case 11: vx = 16; break;
case 1 :
case 5 : vx = 20; break;
case 4 :
case 7 : vx = 24; break;
}
if (year > 1900) // 1900 was not a leap year
year -= 1900;

ix = ((year - 21) % 28) + vx + (month > 2); // take care of February
tx = (ix + (ix / 4)) % 7 + day; // take care of leap year

return (tx % 7);
}

rsquareshelke 13Apr2011 16:26

Re: given month, day, year, returns day of week, eg. Monday = 0 etc.
 
what u want actually,

Logic error or compilation error?

abhi150783 13Apr2011 17:45

Re: given month, day, year, returns day of week, eg. Monday = 0 etc.
 
Well I want to know any logical error if any in this code.
Thx


All times are GMT +5.5. The time now is 01:39.