#include<iostream> //use iostream.h in TurboC++
#include<conio.h>
using namespace std; //comment this line in TurboC++
int dayofweek(int d,int m,int y)
{
static int t[]={0,3,2,5,0,3,5,1,4,6,2,4};
y-=m<3;
/*if(m<3) //this (if) line and the above line of code is same as for the functioning aspect
y-=m;*/
return(y + y/4 - y/100 + y/400 + t[m-1] + d) % 7;
}
int main(void)
{
int d,m,y;
cout<<"\nDay Name Finder \"Enter the below data to find the day on that date:\" ";
cout<<"\n\nEnter date: ";
cin>>d;
cout<<"\nEnter Month: ";
cin>>m;
cout<<"\nEnter Year: ";
cin>>y;
cout<<"\nThe Day on this date is ->: ";
switch(dayofweek(d,m,y))
{
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(); //Use this line in TurboC++ to hold Console Screen
}
No comments:
Post a Comment