Home > Back-end >  Values calculated week
Values calculated week

Time:11-05

Programming implementation: input a year, and this year's what day is on January 1, requires the use of the form (e.g., "Saturday") in Chinese output, and can not use the limit cycle structure, assume that from the first day, the implementation of the Gregorian calendar, and January 1 as 1 AD on Monday, the Gregorian calendar is 400 97 leap leap rules, also can be summarized as: four leap best don't leap, four hundred leap, bosses, can you tell me what's wrong?
# include & lt; stdio.h>
Int main ()
{
Int year, t, s, day;

The scanf (" % d ", & amp; Year);

T=(year 1)/4;

S=(year 1) % 4;

The switch (s)
{
Case: 0 day=t * (365 * 3 + 366); break;
Case 1: day=t + 365 * (365 * 3 + 366); break;
Case 2: day (365 * 3 + 366)=t * 365 * 2 +; break;
Case 3: day (365 * 3 + 366)=t * 365 * 3 +; break;

}
int i;

I=day % 7;

The switch (I)
{
Case 0: printf (" Monday \ n "); break;
Case 1: printf (" Tuesday \ n "); break;
Case 2: printf (" Wednesday \ n "); break;
Case 3: printf (" Thursday \ n "); break;
Case 4: printf (" Friday \ n "); break;
Case 5: printf (" Saturday \ n "); break;
Case 6: printf (" Sunday \ n "); break;
}
return 0;
}

CodePudding user response:

Have a test case? Hair, don't know where you're wrong is to test error, or other errors?

CodePudding user response:

 # include & lt; stdio.h> 
Int main ()
{
Int year, t, s, day;

The scanf (" % d ", & amp; Year);

T=(year 1)/4;

S=(year 1) % 4;

The switch (s)
{
Case: 0 day=t * (365 * 3 + 366); break;
Case 1: day=t + 365 * (365 * 3 + 366); break;
Case 2: day (365 * 3 + 366)=t * 365 * 2 +; break;
Case 3: day (365 * 3 + 366)=t * 365 * 3 +; break;

}
int i;

I=day % 7;

The switch (I)
{
Case 0: printf (" Sunday \ n "); break;
Case 1: printf (" Monday \ n "); break;
Case 2: printf (" Tuesday \ n "); break;
Case 3: printf (" Wednesday \ n "); break;
Case 4: printf (" Thursday \ n "); break;
Case 5: printf (" Friday \ n "); break;
Case 6: printf (" Saturday \ n "); break;
}
return 0;
}

For your reference ~

Case 0 to Sunday, followed by modifying the value corresponding to the week I can ~

Don't case0 is 7 0 7%? How to change the 0 to Monday?

CodePudding user response:

You don't say, four leap best don't leap, four hundred leap, you put 100200300500600,,,, these give a leap year, again the results have a problem for certain
  • Related