Problem 19 solution
More...
#include <stdio.h>
◆ get_month_days()
char get_month_days |
( |
short |
month | ) |
|
Function to get the number of days in a month.
- Parameters
-
month | month identified by an integer -
0 = Jan and 11 = December
|
- Returns
- number of days in given month
- Note
- For February, adjust for leap year outside the function.
◆ is_leap_year()
char is_leap_year |
( |
short |
year | ) |
|
Check if input year is a leap year.
- Parameters
-
- Returns
- 1 if input year is a leap year
-
0 if input year is not a leap year
43 if ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)))
◆ main()
int main |
( |
int |
argc, |
|
|
char ** |
argv |
|
) |
| |
Main function.
81 int count_sundays = 0;
82 const short start_year = 1901;
83 const short end_year = 2000;
91 for (
int year = start_year; year <= end_year; year++)
94 for (
char month = 0; month < 12; month++)
100 if (year == end_year && month == 11)
105 if (is_leap && month == 1)
109 if (year == end_year)
111 printf(
"Year: %d\t Month: %d\t Days: %d\t First of day: %s\n",
112 year, month, days, day_string(start_day));
121 start_day = ((days % 7) + start_day) % 7;
130 "Total number of Sundays that happened on the 1st of a month in the "
131 "last century: %d\n",
char is_leap_year(short year)
Check if input year is a leap year.
Definition: sol1.c:41
char get_month_days(short month)
Function to get the number of days in a month.
Definition: sol1.c:15