C language classic algorithm: Enter a day of one month, judgment this day is the first day of this year?

xiaoxiao2021-03-14  190

Topic: Enter a day in a certain year, judging this day is the first day of this year?

1. Program analysis: Take March 5 as an example, you should first add the first two months, then add 5 days, the first day of this year, special

Situation, leap year and enter the month greater than 3 times more than 3 times.

2. Program source code:

Main ()

{

Int Day, Month, Year, SUM, LeAP;

Printf ("/ NPLEASE INPUT Year, Month, day / n");

Scanf ("% D,% D,% D", & Year, & Month, & Day);

Switch / * first calculate the total number of days before the month * /

{

Case 1: SUM = 0; Break;

Case 2: SUM = 31; BREAK;

Case 3: Sum = 59; Break;

Case 4: Sum = 90; Break;

Case 5: Sum = 120; Break;

Case 6: SUM = 151; BREAK;

Case 7: SUM = 181; BREAK;

Case 8: SUM = 212; Break;

Case 9: Sum = 243; Break;

Case 10: Sum = 273; Break;

Case 11: Sum = 304; Break;

Case 12: Sum = 334; Break;

Default: Printf ("Data Error"); BREAK;

}

SUM = SUM DAY; / * plus a certain day * /

IF (Year% 400 == 0 || (Year% 4 == 0 && Year% 100! = 0)) / * Judgment is a leap year * /

LEAP = 1;

Else

Leap = 0;

IF (Leap == 1 && Month> 2) / * If it is a leap year and the month is greater than 2, the total number of days should add one day * /

SUM ;

Printf ("IT IS the% DTH Day.", SUM;

转载请注明原文地址:https://www.9cbs.com/read-129297.html

New Post(0)