switch month case 12 sum += 30; case 11 sum += 31; case 10 sum += 30; case 9 sum += 31; case 8 sum += 31; case 7 sum += 30; case 6 sum += 31; case 5 sum += 30; case 4 sum += 31; case 3 if year 4 ==
This code is a switch statement that takes in a variable "month" and calculates the total number of days up to that month, based on the year and the number of days in each month.
If the month is December (12), it adds 30 days to the total sum. If the month is November (11), it adds 31 days to the sum. It continues through each month until it reaches March (3).
For March, it checks if the year is a leap year (divisible by 4 but not by 100, or divisible by 400). If it is, it adds 29 days to the sum. Otherwise, it adds 28 days to the sum.
After March, it adds the remaining months and days to the sum. If the month is February (2), it adds 31 days. If the month is January (1), it adds the number of days in that month (specified by the variable "day").
This code assumes that the variable "year" is defined somewhere else in the program.
原文地址: http://www.cveoy.top/t/topic/bv2f 著作权归作者所有。请勿转载和采集!