#include <iostream.h>
#include <conio.h>
#include <stdlib.h>

int Days(int Month,int Year);
int Days_Passed(int Month,int Year,int Date);
int Day(int Month,int Year,int Date);

void main()
{
	int m,y,d;
	clrscr();

	cout << "\n\n--------------------> Mr. Calendar <------------------";
	do
	{
	cout << "\n\n-----------------------------------------------------------------\n";
	cout << "Enter month : ";		cin >> m;
	cout << "Enter year : ";		cin >> y;
	cout << "Enter Date : ";		cin >> d;
	cout << "\nThe numbers of days in the given month are " << Days(m,y);
	cout << "\nThe total numbers of days since the beg. of year till the given month are " << Days_Passed(m-1,y,d);
	cout << "\nThe day is " << Day(m-1,y,d);

	cout << "\n\nPress Esc to quit , any other key to try again.......";
	} while (getch()!=27);

}

int Days(int m,int y)
{
	return 30+(m+m/8)%2+(1-((3*m-6)/(3*m-7))-1/m)*(-1-(3*(y%4))/(3*(y%4)-1)-3*(y%400)/(3*(y%400)-1)+3*(y%100)/(3*(y%100)-1));
}

int Days_Passed(int m ,int y,int d)
{
	return d+((m+(m%2))/2+(m/8)*(1-(m%2)))*31+(m/2-(m/8)*(1-(m%2)))*30+((3*m-3)/(3*m-4))*(-2+1-(3*(y%4))/(3*(y%4)-1)-3*(y%400)/(3*(y%400)-1)+3*(y%100)/(3*(y%100)-1));
}


int Day(int m ,int y,int d)
{
	return (d+((m+(m%2))/2+(m/8)*(1-(m%2)))*31+(m/2-(m/8)*(1-(m%2)))*30+((3*m-3)/(3*m-4))*(-2+1-(3*(y%4))/(3*(y%4)-1)-3*(y%400)/(3*(y%400)-1)+3*(y%100)/(3*(y%100)-1))+(y+((y-1)/4)-(y/100)+(y/400))-1) % 7;
}

