用do+while改写根据年份月份输出该月天数的程序,使程序能够判断10个年份月份的天数
时间: 2024-06-15 14:06:04 浏览: 14
使用do-while循环可以实现根据年份月份输出该月天数的程序,并且可以判断10个年份月份的天数。下面是使用do-while循环改写的程序:
```c++
#include <iostream>
using namespace std;
int main() {
int year, month;
int days;
int count = 1; do {
cout << "请输入第" << count << "个年份和月份:" << endl;
cin >> year >> month;
// 判断天数
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;
}
cout << year << "年" << month << "月的天数为:" << days << endl;
count++;
} while (count <= 10);
return 0;
}
```