发布网友 发布时间:2023-06-17 19:47
共1个回答
热心网友 时间:2024-01-29 22:33
楼上写的程序BUG太多,你能处理任意输入日期后你能判断那是星期几吗?这是我写的 #include<stdio.h> int year1=2007,month1=1,day1=1; char week[7][9]={"Monday","Tuesday","Wednesday","Thusday","Friday","Saturday","Sunday"}; int Month1[]={31,28,31,30,31,30,31,31,30,31,30,31}; int Month2[]={31,29,31,30,31,30,31,31,30,31,30,31}; int number1,number2,number3; void main() { int i,j,XingQi; printf("please input the year:\n"); scanf("%d",&number1); printf("please input the month:\n"); scanf("%d",&number2); printf("please input the day:\n"); scanf("%d",&number3); if(Compare()==1) { j=Account2(); XingQi=j%7; printf("Today is :%s\n",week[XingQi]); } else if(Compare()==0) { j=Account1(); XingQi=j%7; printf("Today is :%s\n",week[7-XingQi]); } getch(); } int Account1() { int count=0,k,i,j=0,leap,daynumber,amount; int a=0; k=year1-number1; for(i=number1+1;i<year1;i++) { if(LeapDistinguish(i)==1) count++; } if(LeapDistinguish(number1)==1) { for(a=0;a<number2-1;a++) { j=j+Month2[a]; } } else if(LeapDistinguish(number1)==0) for(a=0;a<number2-1;a++) { j=j+Month1[a]; } daynumber=number3-day1; amount=365*k+count-j-daynumber; return amount; } int Account2() { int k,i,j=0,leap=0,daynumber,amount; k=number1-year1; for(i=year1;i<number1;i++) { if(LeapDistinguish(i)==1) leap++; } if(LeapDistinguish(number1)==1) { for(i=0;i<number2-1;i++) { j=j+Month2[i]; } } else if(LeapDistinguish(number1)==0) for(i=0;i<number2-1;i++) { j=j+Month1[i]; } daynumber=number3-day1; amount=365*k+leap+j+daynumber; return amount; } int Compare() { if(number1>=year1) return 1; else return 0; } int LeapDistinguish(int i) { if(i%4==0&&i%100!=0||i%400==0) return 1; else return 0; }