Coders Packet

Zeller's Algorithm Using C++

By Adarsh Kumar Jha

Zeller's congurence is an algorithm proposed by Christian Zeller which calculate the day of the weekfor a given year.

Zeller's congruence is an algorithm proposed by Christian Zeller which calculates the day of the week for a given year. The C++ program is used to find the day of the week for a given year, month, and date by a method known as the Zeller's Algorithm.
The algorithm uses the formula which is:
h = (d + (13 * (m + 1) / 5) + (y) + (y / 4) - (y / 100) + (y / 400)) mod 7
where,
1. 'h' is the day of the week (if h=1 then Sunday, if h=2 then Monday, and so on).
2. 'd' is the day of the month.
3. 'm' is a number corresponding to the month of the year.
4. 'y' is the year.

Download Complete Code

Comments

  • Sysio :

    The code is erroneous. The expression

    x % 7

    cannot result in 7 so the last if branch should read

    if(h == 0) ...

    instead of

    if(h == 7)...

    otherwise Saturdays will never appear on output.

  • Reply to this comment



    Download Packet

    Reviews Report

    Submitted by Adarsh Kumar Jha (Adarsh)

    Download packets of source code on Coders Packet