Write a program in C++ Find out the Day of The Given Date ...
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<iostream.h>
void main()
{
int i,z1,j,dd,mm,yy,od,x,od1,od2,y,z,w,od11,od12;
clrscr();
char d[7][20]={"sunday","monday","tuesday","wednesday","thursday","friday","saturday" };
char m[12][20]={"january","february","march","april","may","june","july","august","september","october","november","december" };
cout<<"\nEnter the Date";
cin>>dd>>mm>>yy;
cout<<dd<<"-"<<mm<<"-"<<yy;
//cout<<"\ncalculate the period";
x=yy-1;
od=x%400; //od is the zero odd day
od11=od/100;
od12=od%100;
od1=od12/4; //od1 calculate the leap year
od2=od12-od1; //od2 calculate ordinary year
y=od1*2+od2*1;
w=od11*5;
if(w<=6)
w=w;
else
w=w%7;
z1=y%7;
z=(w+z1)%7;//calucate odd day
cout<<"\n\n";
cout<<od12<<" years = "<<od1<<" + "<<od2<<" ordinary years = "<<y<<"odd days";
cout<<"\n\n";
cout<<yy<<" years have=("<<w<<"+"<<z1<<")="<<z<<" odd days";
cout<<"\n\n";
if(yy%4==0)
{
m[0][20]=31;
m[1][20]=29;
m[2][20]=31;
m[3][20]=30;
m[4][20]=31;
m[5][20]=30;
m[6][20]=31;
m[7][20]=31;
m[8][20]=30;
m[9][20]=31;
m[10][20]=30;
m[11][20]=31;
}
else
{
m[0][20]=31;
m[1][20]=28;
m[2][20]=31;
m[3][20]=30;
m[4][20]=31;
m[5][20]=30;
m[6][20]=31;
m[7][20]=31;
m[8][20]=30;
m[9][20]=31;
m[10][20]=30;
m[11][20]=31;
}
int s=0,s1,s2,t;
for(i=0;i<mm-1;i++)
{
s=s+m[i][20];
}
s1=s+dd;
s2=s1%7;
t=(z+s2)%7;
cout<<s1;
// cout<<t;
cout<<"\ntotal day="<<t;
//cout<<"\n"<<s2;
cout<<"\n\n";
cout<<"The Day of the Given date "<<dd<<"-"<<mm<<"-"<<yy<<"==>>"<<d[t];
getch();
}
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<iostream.h>
void main()
{
int i,z1,j,dd,mm,yy,od,x,od1,od2,y,z,w,od11,od12;
clrscr();
char d[7][20]={"sunday","monday","tuesday","wednesday","thursday","friday","saturday" };
char m[12][20]={"january","february","march","april","may","june","july","august","september","october","november","december" };
cout<<"\nEnter the Date";
cin>>dd>>mm>>yy;
cout<<dd<<"-"<<mm<<"-"<<yy;
//cout<<"\ncalculate the period";
x=yy-1;
od=x%400; //od is the zero odd day
od11=od/100;
od12=od%100;
od1=od12/4; //od1 calculate the leap year
od2=od12-od1; //od2 calculate ordinary year
y=od1*2+od2*1;
w=od11*5;
if(w<=6)
w=w;
else
w=w%7;
z1=y%7;
z=(w+z1)%7;//calucate odd day
cout<<"\n\n";
cout<<od12<<" years = "<<od1<<" + "<<od2<<" ordinary years = "<<y<<"odd days";
cout<<"\n\n";
cout<<yy<<" years have=("<<w<<"+"<<z1<<")="<<z<<" odd days";
cout<<"\n\n";
if(yy%4==0)
{
m[0][20]=31;
m[1][20]=29;
m[2][20]=31;
m[3][20]=30;
m[4][20]=31;
m[5][20]=30;
m[6][20]=31;
m[7][20]=31;
m[8][20]=30;
m[9][20]=31;
m[10][20]=30;
m[11][20]=31;
}
else
{
m[0][20]=31;
m[1][20]=28;
m[2][20]=31;
m[3][20]=30;
m[4][20]=31;
m[5][20]=30;
m[6][20]=31;
m[7][20]=31;
m[8][20]=30;
m[9][20]=31;
m[10][20]=30;
m[11][20]=31;
}
int s=0,s1,s2,t;
for(i=0;i<mm-1;i++)
{
s=s+m[i][20];
}
s1=s+dd;
s2=s1%7;
t=(z+s2)%7;
cout<<s1;
// cout<<t;
cout<<"\ntotal day="<<t;
//cout<<"\n"<<s2;
cout<<"\n\n";
cout<<"The Day of the Given date "<<dd<<"-"<<mm<<"-"<<yy<<"==>>"<<d[t];
getch();
}
No comments:
Post a Comment