This is a neat little program to calculate the date of easter in any given year. The principle is based on the julian calendar.
Calculating Easter Sunday
#include <iostream>
#include <string>
#include <cmath>
#include <time.h>
#include <stdio.h>
#include <iomanip>
using namespace std;
int main()
{
cout<< "Enter year of inquiry"<<endl;
int x;//The year for which it is desired to compute Easter Sunday.
cin>> x;//The 4-digit year.
if (x<0001 || x>9999)
cout<<"The year has to be between 0001 & 9999!"<<endl;
int a = x % 19;//The remainder of the division of x by 19.
int b = x % 4;//The remainder of the division of x by 4.
int c = x % 7;//The remainder of the division of x by 7.
int d = (19 * a + 24) % 30;//The remainder of the division of (19*a + 24) by 30.
int e = (2 * b + 4 * c + 6 * d + 5) % 7;//The remainder of the division of (2*b+4*c+6*d+5) by 7.
int sunday = (22 + d + e);//The calculation of easter sunday.
int month = 3; // March
if(sunday > 31)
{
month = 4;
sunday -= 31;
}
cout<<setw(4)<< "Day" <<setw(8)<< "Month" <<setw(8)<< "Year"<<endl;
cout<<endl;
cout<<"--------------------"<<endl;
cout<<endl;
cout<<setw(4)<<sunday<<setw(6)<<month<<setw(10)<<x<<endl;
return 0;
}
muthu_tek 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.