C语言用if嵌套语句输入1~12数字输出月份的英文
时间: 2023-04-05 10:04:53 浏览: 95
C语言if语句用法
5星 · 资源好评率100%
答案:可以。以下是示例代码:
```c
#include <stdio.h>
int main() {
int month;
printf("请输入1~12之间的数字:");
scanf("%d", &month);
if (month == 1) {
printf("January\n");
} else if (month == 2) {
printf("February\n");
} else if (month == 3) {
printf("March\n");
} else if (month == 4) {
printf("April\n");
} else if (month == 5) {
printf("May\n");
} else if (month == 6) {
printf("June\n");
} else if (month == 7) {
printf("July\n");
} else if (month == 8) {
printf("August\n");
} else if (month == 9) {
printf("September\n");
} else if (month == 10) {
printf("October\n");
} else if (month == 11) {
printf("November\n");
} else if (month == 12) {
printf("December\n");
} else {
printf("输入错误!\n");
}
return 0;
}
```
阅读全文