代码写的不严谨。

网上也有很多计算任何一天是星期几的C语言源代码,不过,有些代码含有一点点小错误。像闰年的分辨啊,或者是每个月的天数,再或者星期的计算公式,都是比较细微的环节,出一点错误都有可能导致结果不正确。这一点,我都进行过验证。下面我选出的这组代码,结构清晰,语法明确。希望能给各位C的爱好者或者要考计算机二级的同学们一点点帮助!当然,有错误的话,也请各位指出!

代码如下:

 #include <stdio.h>
int main()
{
int day,mn,yr,i,days=,s,k;
int mont[]={,,,,,,,,,,,,};
char wek[][]={ {'S','u','n','d','a','y'},
{'M','o','n','d','a','y'},
{'T','u','e','s','d','a','y'},
{'W','e','d','n','s','d','a','y'},
{'T','h','u','r','s','d','a','y'},
{'F','r','i','d','a','y'},
{'S','a','t','u','r','d','a','y'}
};
printf("Inpute the date (year-month-day):");
scanf("%d-%d-%d",&yr,&mn,&day);
if (yr%==||yr%==||yr%==)
mont[]=;
else
mont[]=;
for (i=;i<mn;i++)
days+=mont[i];
days+=day;
s=yr-+(int)((yr-)/)-(int)((yr-)/)+(int)((yr-)/)+days;
k=s%;
printf("%d-%d-%d is %s.",yr,mn,day,wek[k]);
return ;
}
05-11 20:04