Algorithms_in_C
1.0.0
Set of algorithms implemented in C.
|
Problem 19 solution More...
#include <stdio.h>
Functions | |
char | get_month_days (short month) |
char | is_leap_year (short year) |
int | main (int argc, char **argv) |
Problem 19 solution
char get_month_days | ( | short | month | ) |
returns number of days in a month. Month is identified by an integer -
0 = Jan and 11 = December
For February, adjust for leap year outside the function.
char is_leap_year | ( | short | year | ) |
int main | ( | int | argc, |
char ** | argv | ||
) |
Main function
Let us identify days i.e., Sunday thru Saturday with integers - 0 thru 6 respectively Jan 1 1901 was a Tuesday
These two for-loops count the start of day for the next month. Hence, we have to skip the last December count
Main Algorithm: every week has 7 days hence, the start of next day would be modulo 7 add to this, the current start date and ensure the result is still modulo 7!