// 请在下面补充代码,实现函数printMonth(c++实现) /*************** Begin **************/ // 函数days:计算某年某月有多少天 // 参数:year-年,month-月 // 返回值:该年该月的天数
时间: 2024-03-18 09:38:05 浏览: 59
```cpp
#include <iostream>
int days(int year, int month) {
if (month == 2) {
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
return 29;
} else {
return 28;
}
} else if (month == 4 || month == 6 || month == 9 || month == 11) {
return 30;
} else {
return 31;
}
}
void printMonth(int year, int month) {
std::cout << "Year: " << year << ", Month: " << month << std::endl; std::cout << "Days: " << days(year, month) << std::endl;
}
int main() {
int year, month;
std::cout << "Enter year: ";
std::cin >> year;
std::cout << "Enter month: ";
std::cin >> month;
printMonth(year, month);
return 0;
}
```
阅读全文