Home > Back-end >  Introduction to the C language problem for help: mother's day is the second Sunday in May each
Introduction to the C language problem for help: mother's day is the second Sunday in May each

Time:10-30

#include
Int main ()
{
Int year, day, leapyear=0, I, whichday;
The scanf (" % d ", & amp; Year);
For (I=1900; i<=year; I++)
{
If ((I %==0 400) | | ((I % 100!=0) & amp; & (I % 4==0))) leapyear +=1;/* find out 1900 to target between several leap year */
}
Day=(((year 1899) * 365 + leapyear) - (31 + 30 + 3 + 31 + 30 + 31 + 30 + 31)) % 7;/* calculated from January 1, 1900 (Monday) to the target in April 30, a total of how many days, and the target in April 30 for week */
If (day==7) whichday=14;
The else whichday=14 - day;
Printf (" % d ", whichday);
return 0;
}


Have the following questions:
1 week to solve the problems in the C language is generally known by default on January 1, 1900 for Monday?
2. Why can take over operations answers for 7
If (day==7) whichday=14;
The else whichday=14 - day;

CodePudding user response:

My personal understanding should be output day-of-week, such as specific for more than 100 days, rather than the output? So they will take care of week, directly calculate leap year to calculate the number of days before may plus the 14

CodePudding user response:

For more than 7 take seven, could not possible for a value between 0 ~ 6;
Usually fixed a date of the week, so there is a reference, the day of the week is an anticipation heavy relative time, then have a reference; Such as January 1, 1900 is on Monday

CodePudding user response:

So are there any wrong in the code but run on and there is nothing wrong with

CodePudding user response:

reference w770264484 reply: 3/f
so is there any wrong in the code but on the run and there is nothing wrong with

Yes, just d==7 judgment will not set up, so will always follow the else part of

CodePudding user response:

They melody anyone can explain why - 1899 not 1900!
  • Related