0% found this document useful (0 votes)
25 views2 pages

Calendar

The document contains a C++ program that uses a mental calculation method to determine the day of the week for a given date. It takes in date, month and year as input and outputs the day of the week. The program uses logic to calculate an odd value based on the year and month to determine the day.

Uploaded by

prabu amarnath
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views2 pages

Calendar

The document contains a C++ program that uses a mental calculation method to determine the day of the week for a given date. It takes in date, month and year as input and outputs the day of the week. The program uses logic to calculate an odd value based on the year and month to determine the day.

Uploaded by

prabu amarnath
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<iostream.

h>

#include<conio.h>

void main()

int dd,mm,yy,odd,rd,rm,ry,oy1,oy2,day;

cout<<"Enter Date:";cin>>dd;

cout<<"Enter Month:";cin>>mm;

cout<<"Enter Full Year:";cin>>yy;

if(yy%400==0||(yy%4==0&&yy%100!=0))

odd=4;rd=29;

else

odd=3;rd=28;

rm=2;ry=yy-1;

oy1=ry-(ry%100);

odd=odd+(7-(2*(oy1%400))/100);

oy2=ry%100;

odd=odd+(oy2%7)+((oy2/4)%7);

odd=odd%7;

if(mm==1)

if(rd==29)

rd=4;

else

rd=3;

1
if(mm==3)

rd=0;

if(mm!=2&&mm%2==0)

rd=mm;

if(mm==5||mm==7)

rd=mm+4;

if(mm==9||mm==11)

rd=mm-4;

day=(odd+dd-rd)%7;

switch(day)

case 0:cout<<"Sunday";break;

case 1:cout<<"Monday";break;

case 2:cout<<"Tuesday";break;

case 3:cout<<"Wednesday";break;

case 4:cout<<"Thursday";break;

case 5:cout<<"Friday";break;

case 6:cout<<"Saturday";break;

getch();

Anish Prasannan

I year M.Tech CEN

Dear M.Tech students,

The above C ++ programme is written for the mental calculation method (calendar problem) that we learnt in the
class room. We appreciate Anish Prasannan for her efforts in coding this. Anish Prasannan is eager to know
whether there is any flaw in her programme. If you find any error in the above programme, please let Anish
Prasannan know the same. You are also encouraged to discuss the above C programme with your friends or Anish
Prasannan

CIR Aptitude Team

You might also like