当前位置:网站首页>Calculate the day of the week for a specific month, year and day

Calculate the day of the week for a specific month, year and day

2022-06-11 07:11:00 lihongtao8209

One . Detailed analysis

1- The beginning of the problem

Yesterday I went to the library and saw a C Language on the computer . If 2008 year 3 month 1 Sunday is Thursday , that 2008 year 1 month 1 What day is the day of the week ?
Here's what I didn't learn in primary school “ measure ” knowledge .

  1. 8 reduce 1 How much ?
  2. 8 To 1 A few numbers ?
  3. 2 To 8 A few numbers ?

The first question is to make a difference :8-1=7
The second question is that college students have never thought about it , Should be :(8-1)+1=8
The third question will be , There are many solutions , The most basic :(8-2)+1=7

A lot of people “ There are several numbers between two numbers ” This problem is always wrong , Or calculate more 1 individual . The main reason is that there is no repeated training in primary schools . So it is an insurmountable gap to take a programming course in University .

2- The aggravation of the problem

Consider another question

  1. 0 and 10 There are several numbers between them .
  2. 1 and 10 There are several numbers between .

The difficulty of this problem is how to write the general term formula between two numbers . such as d=4 Equal difference sequence of .
3 7 10 14 17
1 2 3 4 5
0 1 2 3 4
ask a question : The general term formula of arithmetic sequence :

a n = a 1 + ( n − 1 ) d a_{n}=a_{1}+(n-1)d an=a1+(n1)d

Its index is 1 As a starting point ? Or to 0 As a starting point ?
Binomial theorem ?
This problem will have a great influence in calculus .

3- The deterioration of the problem

  1. 2008 year 1 month 1 The day is coming 2008 year 3 month 1 A few days away ?
  2. If 2008 year 3 month 1 Sunday is Thursday ,2008 year 1 month 1 What day is the day of the week ?

The difficulty of these two questions is :

  1. To put 1 The days of the month are expanded and the dates are added .
  2. To put 3 The days of the month are expanded and the dates are added .
  3. 1 month 1 Does the day count 1 God ;3 month 1 Is it a day 1 God .
  4. Is the calculation correct ?

4- Solution

A lot of knowledge is ambiguous , Most subjects are mathematics . The world's problems , Only remember not to break . If only I could remember .

Two . Outline development

After running the program code, you can enter :
1
2
2021
Let's calculate 2021 year 2 month 1 What day is the day of the week ?

#include<stdio.h>

int main()
{
    
int year,mon,day;
int days;
int wk;
int weeks[12]={
    31,29,31,30,31,30,31,31,30,31,30,31};
days=0;
printf("day:");
scanf ("%d", &day);
days+=day;
printf("month:");
scanf ("%d", &mon);
for(int i=0;i<mon-1;i++)
{
    
   days=days+weeks[i];
}

printf("year:");
scanf ("%d", &year);
if (year%4==0&& year%100!=0 || year%400==0)
{
    
  printf("(leap year.)");
}
else
{
    days--;}

year-=1;
wk=(year+year/4-year/100+year/400+days) %7;
printf("%d,%d", year+1,wk);

    return 0;
}

1. Principles of Mathematics

If 20210101 It's Friday , And a week 7 God .
set up r=1%7=1 It is Friday .
that a ≡ b ( m o d 7 ) a \equiv b(mod 7) ab(mod7)=1 It's all Friday .
Here are some explanations :

  1. 2021 year 01 month 01 Day is the first 1 God .
  2. 2021 year 01 month 08 Day is the first 8 God .
  3. 2021 year 12 month 31 Day is the first 365 God .

2. Ordinary year

3. Leap year

4. Starting year

5. The end year

原网站

版权声明
本文为[lihongtao8209]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203020522382679.html