Featured
- Get link
- X
- Other Apps
C++ Program to print day for any date from 1 jan 1900
#include<iostream.h>
#include<conio.h>
struct DATE
{ long d,m,y;
}D1,D2;
char weekdays[7][10]=
{"MONDAY","TUESDAY","WEDNESDAY",
"THURSDAY","FRIDAY","SATURDAY","SUNDAY"};
unsigned long totdays(DATE,DATE);
void main()
{
D1.d=1;
D1.m=1;
D1.y=1900;
char ans;
do
{
clrscr();
cout<<"\nEnter the Date: First Enter Day then Month then Year\n";
cin>>D2.d;
cin>>D2.m;
cin>>D2.y;
unsigned long totaldays=totdays(D1,D2);
unsigned long rem=totaldays%7;
cout<<"\nThe day on "<<D2.d<<"/"<<D2.m<<"/"<<D2.y<<" Is:"<<weekdays[rem];
cout<<"\n\nDo you want to see another day for a date? y/n\n";
cin>>ans;
}while(ans=='y');
getch();
}
unsigned long totdays(DATE D1,DATE D2)
{
unsigned long sum=0;
for(unsigned long i=1900;i<D2.y;i++)
{
if(i%100==0 && i%400==0)
sum+=366;
else if(i%100!=0&&i%4==0)
sum+=366;
else
{ sum+=365;
}
}//end for
for(i=1;i<D2.m;i++)
{
if(i==1||i==3||i==5||i==7||i==8||i==10||i==12)
{
sum+=31;
}
else if(i==4||i==6||i==9||i==11)
{
sum+=30;
}
else if(i==2)
{ if(D2.y%100==0 && D2.y%400==0)
sum+=29;
else if(D2.y%100!=0 && D2.y%4==0)
sum+=29;
else
sum+=28;
}//end if outer
}//end for
sum+=D2.d;
return sum-1;
}//end function
#include<conio.h>
struct DATE
{ long d,m,y;
}D1,D2;
char weekdays[7][10]=
{"MONDAY","TUESDAY","WEDNESDAY",
"THURSDAY","FRIDAY","SATURDAY","SUNDAY"};
unsigned long totdays(DATE,DATE);
void main()
{
D1.d=1;
D1.m=1;
D1.y=1900;
char ans;
do
{
clrscr();
cout<<"\nEnter the Date: First Enter Day then Month then Year\n";
cin>>D2.d;
cin>>D2.m;
cin>>D2.y;
unsigned long totaldays=totdays(D1,D2);
unsigned long rem=totaldays%7;
cout<<"\nThe day on "<<D2.d<<"/"<<D2.m<<"/"<<D2.y<<" Is:"<<weekdays[rem];
cout<<"\n\nDo you want to see another day for a date? y/n\n";
cin>>ans;
}while(ans=='y');
getch();
}
unsigned long totdays(DATE D1,DATE D2)
{
unsigned long sum=0;
for(unsigned long i=1900;i<D2.y;i++)
{
if(i%100==0 && i%400==0)
sum+=366;
else if(i%100!=0&&i%4==0)
sum+=366;
else
{ sum+=365;
}
}//end for
for(i=1;i<D2.m;i++)
{
if(i==1||i==3||i==5||i==7||i==8||i==10||i==12)
{
sum+=31;
}
else if(i==4||i==6||i==9||i==11)
{
sum+=30;
}
else if(i==2)
{ if(D2.y%100==0 && D2.y%400==0)
sum+=29;
else if(D2.y%100!=0 && D2.y%4==0)
sum+=29;
else
sum+=28;
}//end if outer
}//end for
sum+=D2.d;
return sum-1;
}//end function
- Get link
- X
- Other Apps
Labels:
C++ program to display day on a given date
C++ program to print date day
C++ Program to print day for any date from 1 jan 1900
display day for a date in c++
Popular Posts
C++ program to display numbers which get reversed after multiplying by 4
- Get link
- X
- Other Apps
Comments
Post a Comment