delphi7 计算星期几 讲个思路,提醒以下语句,谢谢
3个回答
2010-10-16
展开全部
#include <iostream.h>
#include<math.h>
#define W (y%400==0)||(y%4==0&&y%100!=0)
int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int b[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};
long day(long,long,long);
void print()
{cout<<"输入有误!请重新输入:"<<endl;}
void main()
{long y,i=1,m,d,t;
long alls;
cout<<"开始运行程序:";
while(i!=0)
{cout<<"请输入日期:"<<endl;
cout<<"年:";cin>>y;
cout<<"月:";cin>>m;
while(m>12)
{print();
cout<<"月:";cin>>m;}
cout<<"日:";cin>>d;
if(W)
while(d>b[m]){
print();
cout<<"日:";cin>>d;}
else while(d>a[m]){
print();
cout<<"日:";cin>>d;}
if(y==1)
alls=day(y,m,d);
else if(y>1){
t=(y-1)/4-(y-1)/100+(y-1)/400;
alls=(y-1)*365+t+day(y,m,d);}
cout<<y<<"年"<<m<<"月"<<d<<"日,";
switch(alls%7)
{case 1:cout<<"这天是周一。"<<endl;break;
case 2:cout<<"这天是周二。"<<endl;break;
case 3:cout<<"这天是周三。"<<endl;break;
case 4:cout<<"这天是周四。"<<endl;break;
case 5:cout<<"这天是周五。"<<endl;break;
case 6:cout<<"这天是周六。"<<endl;break;
case 0:cout<<"这天是周日。"<<endl;break;}
cout<<"是否继续?退出请输入0:";
cin>>i;
}}
long day(long y,long m,long d){
long days=0,i;
if(W)
{for(i=1;i<m;i++)
days+=b[i];}
else
{for(i=1;i<m;i++)
days+=a[i];}
return (days+d);
}
#include<math.h>
#define W (y%400==0)||(y%4==0&&y%100!=0)
int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int b[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};
long day(long,long,long);
void print()
{cout<<"输入有误!请重新输入:"<<endl;}
void main()
{long y,i=1,m,d,t;
long alls;
cout<<"开始运行程序:";
while(i!=0)
{cout<<"请输入日期:"<<endl;
cout<<"年:";cin>>y;
cout<<"月:";cin>>m;
while(m>12)
{print();
cout<<"月:";cin>>m;}
cout<<"日:";cin>>d;
if(W)
while(d>b[m]){
print();
cout<<"日:";cin>>d;}
else while(d>a[m]){
print();
cout<<"日:";cin>>d;}
if(y==1)
alls=day(y,m,d);
else if(y>1){
t=(y-1)/4-(y-1)/100+(y-1)/400;
alls=(y-1)*365+t+day(y,m,d);}
cout<<y<<"年"<<m<<"月"<<d<<"日,";
switch(alls%7)
{case 1:cout<<"这天是周一。"<<endl;break;
case 2:cout<<"这天是周二。"<<endl;break;
case 3:cout<<"这天是周三。"<<endl;break;
case 4:cout<<"这天是周四。"<<endl;break;
case 5:cout<<"这天是周五。"<<endl;break;
case 6:cout<<"这天是周六。"<<endl;break;
case 0:cout<<"这天是周日。"<<endl;break;}
cout<<"是否继续?退出请输入0:";
cin>>i;
}}
long day(long y,long m,long d){
long days=0,i;
if(W)
{for(i=1;i<m;i++)
days+=b[i];}
else
{for(i=1;i<m;i++)
days+=a[i];}
return (days+d);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你可以上网络上找一下
有一个用数学方法计算的公式
有一个用数学方法计算的公式
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询