R-Ts NetWorks

Server the Best

How to find the day from any date


Enter any Date For Example 8/8/2012.

Copy the Code given below and paste it in Dev C++ Or Turbo C. 

The program will tell you the day of this date.

Code is Given Below

////////////////////////////////

////////////   Start ///////// ///

/////////////////////////////// 

#include<iostream.h>
#include<conio.h>
int century_no(int yr)


{
int cr;
if((yr>=1500)&&(yr<=1599))
cr=1;
else if((yr>=1600)&&(yr<=1699))
cr=0;
else if((yr>=1700)&&(yr<=1799))
cr=5;
else if((yr>=1800)&&(yr<=1899))
cr=3;
else if((yr>=1900)&&(yr<=1999))
cr=1;
else if((yr>=2000)&&(yr<=2099))
cr=0;
else if((yr>=2100)&&(yr<=2199))
cr=5;
else if((yr>=2200)&&(yr<=2299))
cr=3;
return cr;
}
int year_no(int yr)
{
int w,x,y,z;
w=yr%100;
x=w/4;
y=x+w;
z=y%7;
return z;
}
int month_no(int mn,int yr)
{
int mon;
if(yr%4==0)
{
if(mn==1)
mon=5;
else if(mn==2)
mon=1;
else if(mn==3)
mon=2;
else if(mn==4)
mon=5;
else if(mn==5)
mon=0;
else if(mn==6)
mon=3;
else if(mn==7)
mon=5;
else if(mn==8)
mon=1;
else if(mn==9)
mon=4;
else if(mn==10)
mon=6;
else if(mn==11)
mon=2;
else if(mn==12)
mon=4;
}
else if(yr%4!=0)
{
if(mn==1)
mon=6;
else if(mn==2)
mon=2;
else if(mn==3)
mon=2;
else if(mn==4)
mon=5;
else if(mn==5)
mon=0;
else if(mn==6)
mon=3;
else if(mn==7)
mon=5;
else if(mn==8)
mon=1;
else if(mn==9)
mon=4;
else if(mn==10)
mon=6;
else if(mn==11)
mon=2;
else if(mn==12)
mon=4;
}
return mon;
}
main()
{
int dt,mn,yr,cr,z,mon,all,md,add,fnl;
int ch=1;
cout<<“nntttt CALANDERnn”;
cout<<“ttttMade By : Waqar Hussainnn”;
cout<<“ttttCell No : +92 315 754 7702nn”;
while(ch==1)
{
cout<<“nttEnter Data to find the Daynn”;
cout<<“tDay (For Example 14) : “;
cin>>dt;
cout<<“tMonth (For Example 11) : “;
cin>>mn;
cout<<“tYear (For Example 1991) : “;
cin>>yr;
cout<<endl<<endl;
if((yr%4!=0)&&(mn==2)&&(dt>28))
{
cout<<“tt !! Sorry !!nn”;
cout<<“ttGiven Month has only 28 daysnn”;
}
else if((yr%4==0)&&(mn==2)&&(dt>29))
{
cout<<“ttSorry! Plz Try Againn”;
cout<<“ttThis month has only 29 daysnn”;
}
else
{
cr=century_no(yr);
z=year_no(yr);
mon=month_no(mn,yr);
all=cr+z+mon;
md=all%7;
add=md+dt;
fnl=add%7;
if(fnl==0)
cout<<“ntt The Day is : Sunday “;
else if(fnl==1)
cout<<“ntt The Day is : Monday “;
else if(fnl==2)
cout<<“ntt The Day is : Tuesday “;
else if(fnl==3)
cout<<“ntt The Day is : Wednesday “;
else if(fnl==4)
cout<<“ntt The Day is : Thursday “;
else if(fnl==5)
cout<<“ntt The Day is : Friday “;
else if(fnl==6)
cout<<“ntt The Day is : Saturday “;
cout<<endl<<endl;
}
cout<<“nntttPress Enter”<<endl;
getch();
cout<<“nnnnttPlease Select Your Choice”;
cout<<“nt1 : To Continue”;
cout<<endl;
cout<<“t2 : To Exit”;
cout<<“ntEnter Your Choice < 1/2 > : “;
cin>>ch;
cout<<endl<<endl;
}
getch();
}

////////////////////////////////

////////////   END  ///////// ///

/////////////////////////////// 

 

Advertisements

July 15, 2012 - Posted by | C/C++ Tutorial, Education

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: