1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

given month, day, year, returns day of week, eg. Monday = 0 etc.

Discussion in 'C' started by abhi150783, Apr 13, 2011.

  1. abhi150783

    abhi150783 New Member

    Joined:
    Apr 13, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    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);
    }
     
  2. rsquareshelke

    rsquareshelke New Member

    Joined:
    Dec 30, 2010
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    0
    what u want actually,

    Logic error or compilation error?
     
  3. abhi150783

    abhi150783 New Member

    Joined:
    Apr 13, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Well I want to know any logical error if any in this code.
    Thx
     

Share This Page