题解 | #获得月份天数#
获得月份天数
https://www.nowcoder.com/practice/13aeae34f8ed4697960f7cfc80f9f7f6
#include <stdio.h> int main() { int year = 0; int month = 0; while(scanf("%d %d",&year,&month) == 2) { if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) { printf("%d\n", 31); } else if(month == 4 || month == 6 || month == 9 || month == 11) { printf("%d\n", 30); } else { //判断为闰年 if((year % 4 == 0 && year % 100 !=0) || year % 400 == 0) { printf("%d\n", 29);//闰年的2月为29天 } else { printf("%d\n", 28);//平年的2月为28天 } } } return 0; }