Zeller’s congruence is an algorithm developed by Christian Zeller to calculate the day of the week. The formula is
where: h=(q+²⁶(m+I)/10 + k/4 + i/4 + 5i)%7
• h is the day of the week (0: Saturday, 1: Sunday, 2: Monday, 3: Tuesday, 4: Wednesday, 5: Thursday, 6: Friday).
• q is the day of the month
• m is the month (3: March, 4: April, …, 12: December). January and February are counted as months 13 and 14 of the previous year.
• j is the century (i.e., Year/100).
• k is the year of the century (i.e., year%100)
Note that the division in the formula performs an integer division. Write a program that prompts the user to enter a year, month, and day of the month, and displays the name of the day of the
week. Here are some sample runs:
(Hint: January and February are counted as 13 and 14 in the formula, so you need to convert the user input 1 to 13 and 2 to 14 for the month and change the year to the previous year.)
# Here is a Python3 program to find Find the Day
# function for a Date
def day_sw(h) :
return {
0 : "Saturday",
1 : "Sunday",
2 : "Monday",
3 : "Tuesday",
4 : "Wednesday",
5 : "Thursday",
6 : "Friday",
}[h]
#function for entering month and day and year in a asked order
def Zellercongruence(day, month, year) :
if (month == 1) :
month = 13
year = year - 1
if (month == 2) :
month = 14
year = year - 1
q = day
m = month
k = year % 100;
i = year // 100;
h = q + 13 * (m + 1) // 5 + k + k // 4 + i // 4 + 5 * i
h = h % 7
print(day_sw (h))
# Driver code
Zellercongruence(26, 10, 2020)
#Zellercongruence(dd/mm/year)
# This code is contributed by expert Suhrob Umarov
Comments
Leave a comment