#include <stdio.h>
#include <stdbool.h>
// 判断是否为闰年
bool is_leap_year(int x) {
if (((x % 4 == 0) && (x % 100 != 0)) || (x % 400 == 0)) {
return true;
}
else {
return false;
}
}
// 根据年份和月份获取天数
int get_days_of_month(int year, int month) {
int days[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
if (is_leap_year(year)) {
days[2] = 29; // 如果是闰年,则二月有29天
}
return days[month]; // 返回指定月份的天数
}
int main() {
int year, month, days;
printf("请输入年份和月份(格式:年 月): ");
scanf("%d %d", &year, &month);
days = get_days_of_month(year, month);
printf("%d年%d月有%d天\n", year, month, days);
return 0;
}
计算几几年几月有多少天
于 2024-08-19 22:45:36 首次发布