Intro CS II/spring2020/cal

< Intro CS II‎ | spring2020
Revision as of 15:13, 22 January 2020 by Robert.lowe (talk | contribs) (Created page with "<syntaxhighlight lang="cpp"> /** Computes the weekday of a given date. From Big C++ by Cay Horstmann @param year the year @param month the month (1 = January ......")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Revision as of 15:13, 22 January 2020 by Robert.lowe (talk | contribs) (Created page with "<syntaxhighlight lang="cpp"> /** Computes the weekday of a given date. From Big C++ by Cay Horstmann @param year the year @param month the month (1 = January ......")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
/**
   Computes the weekday of a given date.

   From Big C++ by Cay Horstmann
   @param year the year
   @param month the month (1 = January ... 12 = December)
   @param day the day of the month
   @return the weekday (0 = Sunday ... 6 = Saturday)
*/
int day_of_week(int year, int month, int day)
{
   int y = year; 
   int m = month - 1;

   if (month < 3) { y--; m = m + 4; }
   return (y + y / 4 - y / 100 + y / 400
      + 3 * m + 4 - (m - m / 8) / 2 + day) % 7;
}