In Cpp, Calculate Easter Day And Month For Given Year

#include<iostream>
#include<string>

using namespace std;

void easter(int, int&, int &);
string month(int);

int main(){
    int em, ed, year;
    cout << "What's the year: ";
    cin >> year;
    easter(year, em, ed);
    cout << "Easter Month is " << month(em) << endl;
    cout << "Easter Day is " << ed << endl;
    return 0;
}

void easter(int year, int& em, int &ed){
    int a = year % 19;
    int b = year / 100;
    int c = year % 100;
    int d = b / 4;
    int e = b % 4;
    int f = (b + 8) / 25;
    int g = (b - f + 1) / 3;
    int h = ((19 * a) + b - d - g + 15) % 30;
    int i = c / 4;
    int j = c % 4;
    int k = (32 + (2 * e) + (2 * i) - h - j) % 7;
    int m = (a + (11 * h) + (22 * k) ) / 451;
    em = ( h + k - (7 * m) + 114 ) / 31;
    int p = ( h + k - (7 * m) + 114 ) % 31;
    ed = p + 1;
}

string month(int m){
    string txt[]={"January","February","March","April","May","June","July","August","September","October","November","December"};
    return txt[m-1];
}
Download

Comments

Popular posts from this blog