Sunday, 8 March 2015

Cpp Program to calculate the date of Easter Sunday



This is a Cpp Program which computes the date of Easter Sunday.

The date of the Easter changes from year to year. Generally its is the first sunday after the first full moon of Spring.New Testment says that the crucification of Jesus Christ took place during Passover(which is after first full moon of Spring).

So the date changes every year. An algorithm was invented by a mathematician Carl Friedrich Gauss in 1800 to compute the date of Easter Sunday.




Here is the algorithm by Carl Friedrich Gauss :

Step 1  :  Let Y be the year
Step 2  :  Divide Y by 19 to get a remainder as A
Step 3  :  Divide Y by 100 to get a quotient  B and a remainder C
Step 4  :  Divide B by 4 to get a quotient D and a remainder E
Step 5  :  Divide (8*B+13) by 25 to get a quotient G
Step 6  :  Divide (19*A+B-D-G+15) by 30 to get a remainder H
Step 7  :  Divide C by 4 to get a quotient J and a remainder K
Step 8  :  Divide (A+11*H) by 319 to get a quotient M
Step 9  :  Divide (2*E+2*J-K-H+M+32) by 7 to get a remainder R
Step 10:  Divide (H-M+R+90) by 25 to get a quotient N
Step 11: Divide (H-M+R+N+19) by 32 to get a remainder P


So for a given year Y Easter Sunday falls on day P and month N


PROGRAM : 
#include 

using namespace std;

int main()
{
    int y;
    cout << "Enter Year :\t";
    cin >> y;

    if(y <= 0)
        cout << "\nPlease enter a valid Year\n";
    else
    {
        int a =y%19;
        int b = y/100;
        int c = y%100;
        int d = b/4;
        int e = b%4;
        int g = (8*b+13)/25;
        int h =(19*a+b-d-g+15)%30;
        int j = c/4;
        int k = c%4;
        int m = (a+11*h)/319;
        int r = (2*e+2*j-k-h+m+32)%7;
        int n = (h-m+r+90)/25;
        int p = (h-m+r+n+19)%32;



        cout << "\n\nEaster Sunday for year " << y <<" is  ";
        switch(n)
        {
        case 1:
            cout << "January " << p << endl;
            break;
        case 2:
            cout << "February " << p << endl;
            break;
        case 3:
            cout << "March " << p << endl;
            break;
        case 4:
            cout << "April " << p << endl;
            break;
        case 5:
            cout << "May " << p << endl;
            break;
        case 6:
            cout << "June " << p << endl;
            break;
        case 7:
            cout << "July " << p << endl;
            break;
        case 8:
            cout << "August " << p << endl;
            break;
        case 9:
            cout << "September " << p << endl;
            break;
        case 10:
            cout << "October " << p << endl;
            break;
        case 11:
            cout << "November " << p << endl;
            break;
        case 12:
            cout << "December " << p << endl;
            break;

        }
    }
    return 0;
}


OUTPUT : 
Cpp Program for computing Easter Sunday




Cpp Program for computing Easter Sunday