经过大家的共同努力,我们成功了!下面的源代码是改好的
它的功能是计算任意一天是星期几
请大家分享
#include<iostream>
using std::cin;
using std::cout;
using std::endl;
int main()
{
int bYear[]={31,29,31,30,31,30,31,31,30,31,30,31};
int sYear[]={31,28,31,30,31,30,31,31,30,31,30,31};
cout<<"enter year,month,day:"<<endl;
int year,month,day;
int s1=0,s2=0,s=0,fact=0;
int i;
cin>>year>>month>>day;
s1=(year-1)+((year-1)/4)-((year-1)/100)+((year-1)/400);
if(year%400||year%4)
{
for(i=0;i<=(month-1);++i)
{
s2=s2+bYear[i];
}
}
if(year%400!=0||year%4!=0)
{
for(i=0;i<=(month-1);++i)
{
s2=s2+sYear[i];
}
}
s2=s2+day;
s=s1+s2;
fact=s%7;
switch(fact)
{
case 0:
cout<<"today is sunday\n";
break;
case 1:
cout<<"today is monday\n";
break;
case 2:
cout<<"today is tuseday\n";
break;
case 3:
cout<<"today is wednesday\n";
break;
case 4:
cout<<"today is thurday\n";
break;
case 5:
cout<<"today is friday\n";
break;
case 6:
cout<<"today is saturday\n";
break;
default:cout<<"this program has bugs.";
}
return 0;
}
谢谢大家!!!!!!!!!!!
[ 本帖最后由 loookc 于 2009-10-17 13:16 编辑 ]
它的功能是计算任意一天是星期几
请大家分享
#include<iostream>
using std::cin;
using std::cout;
using std::endl;
int main()
{
int bYear[]={31,29,31,30,31,30,31,31,30,31,30,31};
int sYear[]={31,28,31,30,31,30,31,31,30,31,30,31};
cout<<"enter year,month,day:"<<endl;
int year,month,day;
int s1=0,s2=0,s=0,fact=0;
int i;
cin>>year>>month>>day;
s1=(year-1)+((year-1)/4)-((year-1)/100)+((year-1)/400);
if(year%400||year%4)
{
for(i=0;i<=(month-1);++i)
{
s2=s2+bYear[i];
}
}
if(year%400!=0||year%4!=0)
{
for(i=0;i<=(month-1);++i)
{
s2=s2+sYear[i];
}
}
s2=s2+day;
s=s1+s2;
fact=s%7;
switch(fact)
{
case 0:
cout<<"today is sunday\n";
break;
case 1:
cout<<"today is monday\n";
break;
case 2:
cout<<"today is tuseday\n";
break;
case 3:
cout<<"today is wednesday\n";
break;
case 4:
cout<<"today is thurday\n";
break;
case 5:
cout<<"today is friday\n";
break;
case 6:
cout<<"today is saturday\n";
break;
default:cout<<"this program has bugs.";
}
return 0;
}
谢谢大家!!!!!!!!!!!
[ 本帖最后由 loookc 于 2009-10-17 13:16 编辑 ]