C Language Source code-calculate the day of the week

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.