Dayaan M. answered 03/02/26
C Programming Tutor with a Bachelor's in Computer Science
Lets start by writing the Gregorian Zeller's Congruence formula (official form) that determines what day it is based on the date entered:
h = (q + (13(m+1)/5) + K + (K/4) + (J/4) - 2J) mod 7
where:
- q - day of month
- m - month (Ex. march = 3, january = 13, etc)
- K - year of the century = year % 100
- J = century = year/100
Note that if the month is lets say January, use 13 and subtract 1 from year or if the month is february, use 14 and subtract 1 from year.
Moreover, the formula should output a number from 0 to 6 where 0 represents Saturday, 1 represents Sunday, 2 represents Monday and so forth...
Lets implement this program using C++ as our programming language:
Comments are provided in the code to state what each part of the code is doing. So, if you input for example 1984 9 4, it outputs:
That day was a Tuesday
Tuesday: Consistency today creates success tomorrow.