Count Sundays
Explore how to develop C++ functions to determine the number of Sundays falling on the first day of the month during the twentieth century. Understand leap year rules and month day counts to manage date calculations effectively, and apply modular arithmetic to track days across years and months. This lesson helps you practice conditional logic and looping through dates to solve a real-world calendar challenge.
We'll cover the following...
Challenge
January 1st, 1900 was a Monday. The months April, June, September, and November have 30 days, whereas the rest have 31 days, except February which has 29 or 28 depending on whether the year is a leap year or not. A leap year occurs on any year evenly divisible by 4, but not on a century unless it is divisible by 400. Write a program to find out how many Sundays fell on the first of the month during the twentieth century (January 1st, 1901 to December 31st, 2000)?
Note: It is given that January 1st, 1900 was a Monday.
For this problem, you will have to write two ...