a program that outputs the day of the week

Asked 2 years ago, Updated 2 years ago, 89 views

I would like you to teach me how to write a program to know the day of the week.
This is what the example should look like.

$./a.out
Year: 1999
Month: 10
Day: 7
October 7th, 1999 is Thursday.

c algorithm

2022-09-30 19:46

3 Answers

You can do it using the Zeller formula.Note that the day of the week is a little special.


2022-09-30 19:46

A year is 365 days, so if you divide the number of years * 365 + the number of days in the year by 7, that's the day of the week.
The number of days in the year required is the number of days from January 1st.
However, the problem is that there is a leap year, which causes a deviation in the above calculations.

So, to be exact, (years * 365 + number of days in the year + number of leap years) divided by 7.

There is a leap year once every four years, but not once every 100 years.
But once every 400 years is a leap year.
Find out how many leap years this has caused.

If the desired year is leap year, there will be one day difference between before February 29th and after February 29th. Be careful.

leap year https://boxil.jp/beyond/a5435/


2022-09-30 19:46

It means that you can take out the total number of days from January 1st, A.D., and put out a little more than seven.
You can find out how to calculate the total number of days by searching the Internet


2022-09-30 19:46

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.