这道题目做很久了,从早上一直到现在,这是一道关于输入年 月 日,求出星期几的题目,我用的是蔡勒公式,但是老师的系统总说有个地方没通过,帮忙看一下,谢谢。拜托了,郁闷一整天了
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main()
{
int y,m,d,a,b,w;
scanf ("%d %d %d",&y,&m,&d);
if(m>=13||m<=0)
{if(d>=31||d<=0)
printf("month and day are wrong.\n");
else printf("month is wrong.\n");}
{if(m==1||m==3||m==5||m==7||m==8||m==10||m==12)
if(d>=32||d<=0) printf("day is wrong.\n");
else {b=y/100;
a=y-b*100;
if(m>=3)
{w=(a+a/4+b/4-2*b+(26*(m+1)/10)+d-1)%7;
if (w<0) printf("%d\n",w=(w%7+7)%7);
else printf ("%d\n",w);
}
else
{b=(y-1)/100,a=y-1-b*100;
w=(a+a/4+b/4-2*b+(26*(m+13)/10)+d-1)%7;
if (w<0) printf("%d\n",w=(w%7+7)%7);
else printf ("%d\n",w);} }
}
{ if(m==4||m==6||m==9||m==10)
if(d>=31||d<=0) printf("day is wrong.\n");
else {b=y/100;
a=y-b*100;
if(m>=3)
{w=(a+a/4+b/4-2*b+(26*(m+1)/10)+d-1)%7;
if (w<0) printf("%d\n",w=(w%7+7)%7);
else printf ("%d\n",w);
}
else
{b=(y-1)/100,a=y-1-b*100;
w=(a+a/4+b/4-2*b+(26*(m+13)/10)+d-1)%7;
if (w<0) printf("%d\n",w=(w%7+7)%7);
else printf ("%d\n",w);} } }
{if(m==2)
{
if ((y%4==0&&y%100!=0)||y%400==0)
{if(d>=30||d<=0) printf("day is wrong.\n");
else {b=y/100;
a=y-b*100;
if(m>=3)
{w=(a+a/4+b/4-2*b+(26*(m+1)/10)+d-1)%7;
if (w<0) printf("%d\n",w=(w%7+7)%7);
else printf ("%d\n",w);
}
else
{b=(y-1)/100,a=y-1-b*100;
w=(a+a/4+b/4-2*b+(26*(m+13)/10)+d-1)%7;
if (w<0) printf("%d\n",w=(w%7+7)%7);
else printf ("%d\n",w);} }}
else {if(d>=29||d<=0) printf("day is wrong.\n");
else {b=y/100;
a=y-b*100;
if(m>=3)
{w=(a+a/4+b/4-2*b+(26*(m+1)/10)+d-1)%7;
if (w<0) printf("%d\n",w=(w%7+7)%7);
else printf ("%d\n",w);
}
else
{b=(y-1)/100,a=y-1-b*100;
w=(a+a/4+b/4-2*b+(26*(m+13)/10)+d-1)%7;
if (w<0) printf("%d\n",w=(w%7+7)%7);
else printf ("%d\n",w);} }} }
}
system("PAUSE");
return 0;
}
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main()
{
int y,m,d,a,b,w;
scanf ("%d %d %d",&y,&m,&d);
if(m>=13||m<=0)
{if(d>=31||d<=0)
printf("month and day are wrong.\n");
else printf("month is wrong.\n");}
{if(m==1||m==3||m==5||m==7||m==8||m==10||m==12)
if(d>=32||d<=0) printf("day is wrong.\n");
else {b=y/100;
a=y-b*100;
if(m>=3)
{w=(a+a/4+b/4-2*b+(26*(m+1)/10)+d-1)%7;
if (w<0) printf("%d\n",w=(w%7+7)%7);
else printf ("%d\n",w);
}
else
{b=(y-1)/100,a=y-1-b*100;
w=(a+a/4+b/4-2*b+(26*(m+13)/10)+d-1)%7;
if (w<0) printf("%d\n",w=(w%7+7)%7);
else printf ("%d\n",w);} }
}
{ if(m==4||m==6||m==9||m==10)
if(d>=31||d<=0) printf("day is wrong.\n");
else {b=y/100;
a=y-b*100;
if(m>=3)
{w=(a+a/4+b/4-2*b+(26*(m+1)/10)+d-1)%7;
if (w<0) printf("%d\n",w=(w%7+7)%7);
else printf ("%d\n",w);
}
else
{b=(y-1)/100,a=y-1-b*100;
w=(a+a/4+b/4-2*b+(26*(m+13)/10)+d-1)%7;
if (w<0) printf("%d\n",w=(w%7+7)%7);
else printf ("%d\n",w);} } }
{if(m==2)
{
if ((y%4==0&&y%100!=0)||y%400==0)
{if(d>=30||d<=0) printf("day is wrong.\n");
else {b=y/100;
a=y-b*100;
if(m>=3)
{w=(a+a/4+b/4-2*b+(26*(m+1)/10)+d-1)%7;
if (w<0) printf("%d\n",w=(w%7+7)%7);
else printf ("%d\n",w);
}
else
{b=(y-1)/100,a=y-1-b*100;
w=(a+a/4+b/4-2*b+(26*(m+13)/10)+d-1)%7;
if (w<0) printf("%d\n",w=(w%7+7)%7);
else printf ("%d\n",w);} }}
else {if(d>=29||d<=0) printf("day is wrong.\n");
else {b=y/100;
a=y-b*100;
if(m>=3)
{w=(a+a/4+b/4-2*b+(26*(m+1)/10)+d-1)%7;
if (w<0) printf("%d\n",w=(w%7+7)%7);
else printf ("%d\n",w);
}
else
{b=(y-1)/100,a=y-1-b*100;
w=(a+a/4+b/4-2*b+(26*(m+13)/10)+d-1)%7;
if (w<0) printf("%d\n",w=(w%7+7)%7);
else printf ("%d\n",w);} }} }
}
system("PAUSE");
return 0;
}