计算生日是星期几(C语言)

编写一个程序,只要输入年月日,就能回答那天是星期几。
计算生日是星期几(C语言)_第1张图片
#include
int main()
{
int year,month,day,sum=0,i;
scanf("%d %d %d",&year,&month,&day);
int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
if((year%40&&year%100!=0)||year%4000) a[2]=29;
sum=(year-1)*365+(year-1)/4-(year-1)/100+(year-1)/400;
for(i=0;i sum=sum+day;
int ans=sum%7;
if(ans1) printf(“Monday\n”);
else if(ans
2) printf(“Tuesday\n”);
else if(ans3) printf(“Wednesday\n”);
else if(ans
4) printf(“Thursday\n”);
else if(ans5) printf(“Friday\n”);
else if(ans
0) printf(“Sunday\n”);
else printf(“Saturday\n”);
return 0;
}

你可能感兴趣的:(计算生日是星期几(C语言))