Pages

Saturday, October 2, 2010

C source code to tell the day when the date is given

#include <stdio.h>
int main ( )
{
int y,m,d,a,b,f;
printf ("enter the date -:(YYYY MM DD)\n");
scanf ("%d %d %d",&y,&m,&d);
if (12>m&&m>0)
{
 if (m<3)
{
m=m+12;
y=y-1;
}
a=2*m+6*(m+1)/10;
b=y+y/4-y/100+y/400;
f=d+a+b+1;
f=f%7;
}
else
{
printf("error\n");
}
switch(f)
{
case 0:
printf ("sunday\n");
break;
case 1:
printf ("Monday\n");
break;
case 2:
printf ("Tuesday\n");
break;
case 3:
printf ("Wednesday\n");
break;
case 4:
printf ("Thursday\n ");
break;
case 5:
printf ("Friday\n");
break;
case 6:
printf ("Saturday\n ");
break;
}
return 0;
}

this source code is very simple you can implement this in any other language very easily. hope you'll like this. anxiously waiting for someones thoughts.