Saturday, December 4, 2010

Day Finder

#include<stdio.h> //pre-processor directives
#include<conio.h>
int main() //start main function
{
int y,m,d,f,a,b,f1;
clrscr();
printf("Enter the date(y,m,d):");
scanf("%d,%d,%d",&y,&m,&d); //read y,m,d
if(m<3) //if month less than 3
{
m+=12;
y--;
}
a=2*m+6*(m+1)/10; //calculation to find the day
b=y+y/4-y/100+y/400;
f1=d+a+b+1;
f=f1%7;
switch(f) //display the day
{
case 0:printf("Sunday");break;
case 1:printf("Monday");break;
case 2:printf("Tuesday");break;
case 3:printf("Wednesday");break;
case 4:printf("Thursday");break;
case 5:printf("Friday");break;
case 6:printf("Saturday");break;
}
getch();
return 0;
}         //end main

No comments:

Post a Comment