Write a program that finds the day of the week for any given date using Zeller’s congruence. Zeller found the following formula to calculate the day of the week using the day of the month, the month, and the year. weekday = (day + 26 * (month + 1) / 10 + year + year / 4 − year /100 + year /400 ) % 7;

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Write a program that finds the day of the week for any given date using Zeller’s congruence. Zeller found the following formula to calculate the day of the week using the day of the month, the month, and the year.

weekday = (day + 26 * (month + 1) / 10 + year + year / 4 − year /100 + year /400 ) % 7;

The formula is based on the following:

  1. There are seven days in the week so the calculation must be done modulo 7.
  2. The first term, day, shows that each day of the month moves the weekday forward by 1.
  3. The second term, 26 * (month + 1) / 10, is the Zeller congruence. Instead of worrying about the number of days in each month, Zeller devised this solution. Zeller’s formula works for a solar system when the year starts from March, not January. Therefore, we must consider the months January and February as months13 and 14 of the previous year. In other words, January of 2017 must be considered as month 13 of year 2016.
  4. The next term, year, moves the week day one day for each year because anon-leap year is 365 and when divided by 7 the result is 1.
  5. The next term, year / 4, is the contribution of the leap year. We know that each year divided by 4 could be a leap year that adds one day to the week day.
  6. The next term, year / 100, is the term that excludes the year divided by 100from the previous year.
  7. The next term, year / 400, is the term that defines if a year divided by 400is a leap year and needs to add 1 to the calculation.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY