说明:
1、公历的全年天数不同
公历平年全年有365天,而公历闰年全年有366天。
2、被整除的特性不同
非整百年的年份中,能被4整除的为闰年,不能被4整除的为平年。如就是闰年,2001年平年。
整百年的年份中,能被400整除的是闰年,不能被400整除的是平年。如2000年是闰年,1900年是平年。
3、2月份的天数不同
闰年的2月有29天,平年的2月就只有28天
代码如下:
#include <stdio.h>#define MONTHS 12int main(void){int days[2][MONTHS]={{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31 } };int year, month;do {printf("Please input year,month:");scanf_s("%d,%d", &year, &month);} while (month < 1 || month>12);if ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0))//闰年29对应数组第二组;{printf("The number of days is %d\n", days[1][month - 1]);}else {//平年28对应数组第一组;printf("The number of days is %d\n", days[0][month - 1]);}return 0;}