I understand that this function is used to get the day number of the first day of that year, so that we can print the date in the correct position, but I would like to know how it works internally and arrives at a result that is always Correct!
int determinedaycode(int year)
{
int daycode;
int d1, d2, d3;
d1 = (year - 1.)/ 4.0;
d2 = (year - 1.)/ 100.;
d3 = (year - 1.)/ 400.;
daycode = (year + d1 - d2 + d3) %7;
return daycode;
}
This function is part of a calendar generator for any year, I will leave the link of the complete code created by CODINGUNIT.
First take into account that the Gregorian calendar is used to make the program. Next, consider leap years (which is where you have second thoughts)
I will comment the code so that it is understood what was explained before.
I hope I have clarified your doubts, greetings.