用c++代码实现输出2022年历每三个月为一行进行打印
时间: 2023-11-22 15:55:46 浏览: 42
以下是实现代码:
```c++
#include <iostream>
using namespace std;
int main() {
int year = 2022;
int month = 1;
while (month <= 12) {
cout << year << "年 ";
if (month <= 3) {
cout << "第1季度:";
} else if (month <= 6) {
cout << "第2季度:";
} else if (month <= 9) {
cout << "第3季度:";
} else {
cout << "第4季度:";
}
for (int i = 0; i < 3 && month <= 12; i++) {
cout << year << "年" << month << "月 ";
month++;
}
cout << endl;
}
return 0;
}
```
输出结果如下:
```
2022年 第1季度:2022年1月 2022年2月 2022年3月
2022年 第2季度:2022年4月 2022年5月 2022年6月
2022年 第3季度:2022年7月 2022年8月 2022年9月
2022年 第4季度:2022年10月 2022年11月 2022年12月
```