输入1~12的一个整数 输出月份的英文全称 用switch语句或if语句
时间: 2023-04-05 09:04:42 浏览: 116
可以回答这个问题。以下是使用if语句的代码:
```
int month = 7;
if (month == 1) {
cout << "January" << endl;
} else if (month == 2) {
cout << "February" << endl;
} else if (month == 3) {
cout << "March" << endl;
} else if (month == 4) {
cout << "April" << endl;
} else if (month == 5) {
cout << "May" << endl;
} else if (month == 6) {
cout << "June" << endl;
} else if (month == 7) {
cout << "July" << endl;
} else if (month == 8) {
cout << "August" << endl;
} else if (month == 9) {
cout << "September" << endl;
} else if (month == 10) {
cout << "October" << endl;
} else if (month == 11) {
cout << "November" << endl;
} else if (month == 12) {
cout << "December" << endl;
} else {
cout << "Invalid month number" << endl;
}
```
以上代码将输出:
```
July
```
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)