当前位置:网站首页>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 .
- 8 reduce 1 How much ?
- 8 To 1 A few numbers ?
- 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
- 0 and 10 There are several numbers between them .
- 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+(n−1)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
- 2008 year 1 month 1 The day is coming 2008 year 3 month 1 A few days away ?
- 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 :
- To put 1 The days of the month are expanded and the dates are added .
- To put 3 The days of the month are expanded and the dates are added .
- 1 month 1 Does the day count 1 God ;3 month 1 Is it a day 1 God .
- 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) a≡b(mod7)=1 It's all Friday .
Here are some explanations :
- 2021 year 01 month 01 Day is the first 1 God .
- 2021 year 01 month 08 Day is the first 8 God .
- 2021 year 12 month 31 Day is the first 365 God .
2. Ordinary year
3. Leap year
4. Starting year
5. The end year
边栏推荐
- 河南高考VS天津高考(2008年-2021年)
- P3327 [sdoi2015] approximate sum (Mobius inversion + formula)
- Saltstack deployment LNMP
- Matplotlib, set coordinate scale size, font / set legend size and font / set vertical and horizontal coordinate name, font and size
- @JsonProperty注解
- Dynamically change the direction of this
- Notes on learning Es5 and ES6
- R语言并行计算实战教程
- P5431 [template] multiplicative inverse 2
- Quality-aware Feature Aggregation Networkfor Robust RGBT Tracking
猜你喜欢
![[matlab WSN communication] a_ Star improved leach multi hop transmission protocol [including source code phase 487]](/img/fd/53776b550390752282cd8797193436.png)
[matlab WSN communication] a_ Star improved leach multi hop transmission protocol [including source code phase 487]

Shutter restraint container assembly

byte和bit的区别

webserver

Heartless sword Chinese English bilingual poem 001 Love
![pycharm出现error.DeprecatedEnv: Env FrozenLake-v0 not found (valid versions include [‘FrozenLake-v1‘])](/img/1c/4013479ce1fc5b0ff2ebeb754f05a9.png)
pycharm出现error.DeprecatedEnv: Env FrozenLake-v0 not found (valid versions include [‘FrozenLake-v1‘])

Leetcode-141. Linked List Cycle

webserver

Outer margin collapse

Menu double linkage effect in uniapp
随机推荐
Android和iOS逆向分析/安全检测/渗透测试框架
Object. Specific implementation and difference between create() and new
【LeetCode】-- 17. Letter combination of telephone number
Niuke wrong question 3.1
MS office level II wrong question record [10]
Flutter 内外边距
12. integer to Roman numeral
Senior openstacker - Bloomberg, vexxhost upgraded to the Gold member of openinfra Foundation
[Xunwei dry goods] opencv test of Godson 2k1000 development board
Drawing with qpainter
資深OpenStacker - 彭博、Vexxhost昇級為OpenInfra基金會黃金成員
Menu double linkage effect in uniapp
[MATLAB image fusion] particle swarm optimization adaptive multispectral image fusion [including source code phase 004]
Xunwei dry goods | Ruixin micro rk3568 development board TFTP & NFS writing (Part 1)
Error occurred in pycharm DeprecatedEnv: Env FrozenLake-v0 not found (valid versions include [‘FrozenLake-v1‘])
生物序列智能分析平台blog(1)
Atomicinteger atomic operation class
P3327 [sdoi2015] approximate sum (Mobius inversion + formula)
Leetcode hot topic 100 topic 6-10 solution
Interview question 02.06 Palindrome linked list