#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
int songay(int,int);
bool namnhuan(int nam);
void InLich(int,int);
int ThuDauTien(int,int);
void main()
{
int nam;
char chon;
do
{
do
{
cout<<"Nhap vao nam(> 1700): ";
cin>>nam;
}while(nam < 1700);
for(int i = 1;i <= 12;i++)
{
cout<<"Thang "<<i<<endl;
InLich(i,nam);
cout<<endl<<endl;
}
cout<<"\nBan co muon tiep tuc khong(y/n): ";
cin>>chon;
system("cls");
}while(chon == 'y');
cout<<"thegiaotb cam on ban da su dung chuong trinh (Xin vui long an Enter de thoat)";
//getch();
}
int songay(int thang,int nam)
{
switch(thang)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
return 31;
case 2:
if(namnhuan(nam))
return 29;
else
return 28;
case 4:
case 6:
case 9:
case 11:
return 30;
}
return 0;
}
bool namnhuan(int nam)
{
return ((nam % 4 == 0 && nam % 100 != 0)||(nam % 400 == 0));
}
void InLich(int thang,int nam)
{
int ngayd = ThuDauTien(thang,nam);
if(ngayd == 0)
ngayd = 7;
int i;
int sn = songay(thang,nam);
cout<<"\nMon\tTUE\tWED\tTHU\tFRI\tSAT\tSun\n";
for(i = 1;i <= ngayd - 1;i++)
cout<<"\t";
for(i = 1;i <= sn;i++)
{
cout<<i<<"\t";
if((i + ngayd - 1) % 7 == 0)
cout<<endl;
}
}
long int funct1 (int nam,int thang)
{
long int result;
if ( thang <= 2 )
nam -= 1; //
result = nam;
return (result);
}
long int funct2 (int thang)
{
long int result;
if ( thang <= 2 )
result = thang + 13;
else
result = thang + 1;
return(result);
}
long int day_count (int thang, int nam)
{
long int number;
number = 1461 * funct1(nam,thang) / 4 + 153 * funct2(thang) / 5 + 1;
return (number);
}
int ThuDauTien(int thang,int nam)
{
long int number_of_days1;
int day_of_week;
number_of_days1 = day_count (thang, nam);
day_of_week = (number_of_days1 - 621049) % 7;
return day_of_week;
}