This program will display month by month calendar for a given year, after compiling the program give a year (Eg: 2020) and see the output.
//By REGU RAM SV
#include<iostream>
using namespace std;
int main() {
int k,l,j,i;
int year;
cin>>year;
cout<<"Year "<<year<<":\n"<<endl;
int mday[12]={31,28,31,30,31,30,31,31,30,31,30,31};
char months[12][15]={"January","February","March","April","May","June","July","August","September","October","November","December"};
if(year%4==0)
{
if(year%100==0)
{
if(year%400==0)
{
mday[1]=29;
}
}
else{
mday[1]=29;
}
}
if(year<=0)
{
cout<<"year "<<year<<" does not exist in gregorian calendar";
return 1;
}
char days[7][15]={"Su","Mo","Tu","We","Th","Fr","Sa"};
int day=3;
int years=2020;
if(years>year)
{
for(;years>year;years--)
{
if((years-1)%4==0)
{
if((years-1)%100==0)
{
if((years-1)%400==0)
{
day=day-2;
if(day<0)
{
day=day+7;
}
}
else
{
day=day-1;
if(day<0)
{
day=day+7;
}
}
}
else
{
day=day-2;
if(day<0)
{
day=day+7;
}
}
}
else
{
day=day-1;
if(day<0)
{
day=day+7;
}
}
}
}
else if(years<year)
{
for(;years<year;years++)
{
if((years)%4==0)
{
if((years)%100==0)
{
if((years)%400==0)
{
day=day+2;
if(day>6)
{
day=day-7;
}
}
else{
day=day+1;
if(day>6)
{
day=day-7;
}
}
}
else{
day=day+2;
if(day>6)
{
day=day-7;
}
}
}
else
{
day=day+1;
if(day>6)
{
day=day-7;
}
}
}
}
for(i=0;i<12;i++)
{
cout<<""<<months[i]<<endl<<"";
for(k=0;k<7;k++)
{
cout<<days[k]<<" ";
}
//mdaymonths
cout<<"\n"<<"";
for(l=0;l<7;l++)
{
if(l!=day)
{
cout<<" ";
}
else
{
cout<<" ";
break;
}
}
//int mday[12]={31,28,31,30,31,30,31,31,30,31,30,31};
for(j=1;j<=mday[i];j++)
{
// cout<<mday[j-1]<<endl;
if(j<9)
{
cout<<j<<" ";
day++;
if(day>6)
{
day=day-7;
cout<<"\n"<<" ";
}
}
else
{
cout<<j<<" ";
day++;
if(day>6)
{
day=day-7;
cout<<"\n";
}
}
}
cout<<"\n";
if(day!=0)
{
cout<<"\n";
}
}
cout<<"If You like our program, share our post \n\t\t\t\t\t Designed by Regu Ram SV";
}
Post a Comment