C语言,输入年和月份,输出该年该月份的天数。
时间: 2024-04-29 15:25:10 浏览: 89
输入年月份求为该年的多少天.c
```c
#include <stdio.h>
int main() {
int year, month;
printf("请输入年份和月份:");
scanf("%d%d", &year, &month);
int days = 0;
if (month == 2) {
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
days = 29;
} else {
days = 28;
}
} else if (month == 4 || month == 6 || month == 9 || month == 11) {
days = 30;
} else {
days = 31;
}
printf("%d年%d月有%d天\n", year, month, days);
return 0;
}
```
阅读全文