Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sstream>
- #include <iostream>
- using namespace std;
- string ZeroPadNumber(int num){
- stringstream ss;
- // the number is converted to string with the help of stringstream
- ss << num;
- string ret;
- ss >> ret;
- // Append zero chars
- int str_length = ret.length();
- for (int i = 0; i < 2 - str_length; i++)
- ret = "0" + ret;
- return ret;
- }
- void EasterDate(int X){ // X = year to compute
- int K, M, S, A, D, R, OG, SZ, OE;
- K = X / 100; // Secular number
- M = 15 + (3 * K + 3) / 4 - (8 * K + 13) / 25; // Secular Moon shift
- S = 2 - (3 * K + 3) / 4; // Secular sun shift
- A = X % 19; // Moon parameter
- D = (19 * A + M) % 30; // Seed for 1st full Moon in spring
- R = D / 29 + (D / 28 - D / 29) * (A / 11); // Calendarian correction quantity
- OG = 21 + D - R; // Easter limit
- SZ = 7 - (X + X / 4 + S) % 7; // 1st sunday in March
- OE = 7 - (OG - SZ) % 7; // Distance Easter sunday from Easter limit in days
- //Easter = DateSerial(X, 3, OG + OE); // Result: Easter sunday as number of days in March
- cout << X << "-" << ZeroPadNumber(((OG + OE)>31)?4:3) << "-" << ZeroPadNumber((((OG + OE)%31)==0)?31:((OG + OE)%31));
- }
- int main ()
- {
- int year;
- do {
- cout << "Put the year: ";
- cin >> year;
- EasterDate(year);
- cout << endl << endl;
- }
- while (year>0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement