Wednesday, June 26, 2013

Write a program to print the day of the given date ?

Problem:
 To write a program to print the day of the given date .example if input is 27/6/2013 output is Thursday

Solution:

#include<stdio.h>
#include<conio.h>

void main()
{
int dd,mm,yyyy,i,x,ly,ry,oday,mday=0,mday2,intex,month[12]={31,28,31,30,31,30,31,31,30,31,30,31};
char day[10]
[10] = {"sunday","monday","tuesday","wednesday","thursday","friday","saturday"};
clrscr();
printf("enter the date in the format of dd mm yyyy\n");
scanf("%d%d%d",&dd,&mm,&yyyy);
yyyy=yyyy-1;
yyyy=yyyy%400;
x=yyyy/100;
if(yyyy>=100)
yyyy=yyyy%100;
ly=yyyy/4;
ry=yyyy-ly;
oday=ly*2+ry+x*5;
oday=oday%7;
for(i=0;i<=mm-2;i++)
mday=mday+month[i];
if((yyyy+1)%4==0&&mm!=2)
mday=mday+1;
mday2=mday+dd+oday;
intex=mday2%7;
if(dd>31||(dd>29&&mm==2)||(dd==29&&mm==2&&(yyyy+1)%4!=0))
printf("\ndate is wrong");
else
printf(" \n %s",day[intex]);
getch();
}


Output:










if any doubt ,please post it on comment .

Like the Post? Do share with your Friends.

1 comment:

  1. i am very thankful to you can you also explain that pls

    ReplyDelete