The code is not strictly written.
There are also a lot of C-language source code that calculates the day of the week, but some of the code contains a little bit of a small error. such as the resolution of a leap year, or the number of days per month, or the calculation formula of the week, is a relatively small part, a bit of error may lead to incorrect results. This, I have been verified. The code I selected below is clearly structured and has a clear syntax. Hope to give you c enthusiasts or to test the computer level two students a little help! Of course, if there are errors, please point out!
The code is as follows:
1#include <stdio.h>2 intMain ()3 { 4 intday,mn,yr,i,days=0, s,k;5 intmont[ -]={0, to, -, to, -, to, -, to, to, -, to, -, to}; 6 Charwek[][9]={ {'S','u','N','D','a','y'}, 7{'M','o','N','D','a','y'}, 8{'T','u','e','s','D','a','y'}, 9{'W','e','D','N','s','D','a','y'}, Ten{'T','h','u','R','s','D','a','y'}, One{'F','R','I','D','a','y'}, A{'S','a','T','u','R','D','a','y'} - }; -printf"Inpute the date (year-month-day):"); thescanf"%d-%d-%d",&yr,&mn,&Day ); - if(yr%4==0|| yr% -==0|| yr% -==0) -mont[2]= in; - Else +mont[2]= -; - for(i=0; i<mn;i++) +days+=Mont[i]; Adays+=Day ; ats=yr-1+(int) ((yr-1)/4)-(int) ((yr-1)/ -)+(int) ((yr-1)/ -)+Days ; -k=s%7; -printf"%d-%d-%d is%s.", Yr,mn,day,wek[k]); - return 0; -}
C Language Source code-calculate the day of the week