Home > Back-end >  104: zero starting point algorithm which day?
104: zero starting point algorithm which day?

Time:12-14

Given a date, this date is output the which day of the year,
Requirements: input data have much group, each group of a line, data format as YYYY/MM/DD,
Analysis: to determine the number of days per month, can use a Switch statement, pay attention to judge whether it is a leap year,
Code: # include

Int main ()
{
Int a, b, c;
While (the scanf (" % d/% d % d ", & amp; A, & amp; B, & amp; C)!=(EOF)
{
Int t, s=0;
for(; b> 0; B -)
{
T=fun (a, b - 1);
S +=t;
}
Printf (" % d \ n ", s + c);
}
}
Int fun (int a, int b)
{
Int t, I;
If ((a % 4==0 & amp; & A % 100!=0) | | (a % 400==0))
t=1;
The else t=0;
The switch (b)
{
Case 0: I=0; break;
Case 1: I=31; break;
Case 3: I=31; break;
Case 5: I=31; break;
Case 7: I=31; break;
Case 8: I=31; break;
Case 10: I=31; break;
Case 12: I=31; break;
Case 4: I=30; break;
Case 6: I=30; break;
Case 9: I=30; break;
Case 11: I=30; break;
Case 2: I=28 + t; break;
}
Return the I;
}
  I published for the first time, just write the program today, may have a lot of shortage, after all to learn C language for the first time, first meeting, please take care!

CodePudding user response:

Sorry, was writing a blog, sent a stick, used for the first time, I'm sorry

CodePudding user response:

Good classmate, continue to work hard ah,,
  • Related