BUPT-homework/semester1/pset7/2-getDays.c

31 lines
666 B
C
Raw Normal View History

2021-11-04 19:42:37 +08:00
// #include <stdio.h>
//
// int getDays(int year, int month);
//
// int main() {
// int year, month;
//
// scanf("%d%d", &year, &month);
// printf("There are %d days in month %d year %d.", getDays(year, month), month,
// year);
//
// return 0;
// }
int getDays(int year, int month) {
if (month == 2) {
if (year % 4 == 0 && year % 100 != 0) {
return 29;
} else if (year % 100 == 0 && year % 400 == 0) {
return 29;
} else {
return 28;
}
} else if (month == 1 || month == 3 || month == 5 || month == 7 ||
month == 8 || month == 10 || month == 12) {
return 31;
} else {
return 30;
}
}