用C编写一个程序,要求用户输入一个两位数然后显示该数的英文单词,用switch语句
时间: 2023-05-11 09:02:32 浏览: 101
Sure, here's the code:
```c
#include <stdio.h>
int main() {
int num;
printf("Please enter a two-digit number: ");
scanf("%d", &num);
switch(num) {
case 10:
printf("Ten\n");
break;
case 11:
printf("Eleven\n");
break;
case 12:
printf("Twelve\n");
break;
case 13:
printf("Thirteen\n");
break;
case 14:
printf("Fourteen\n");
break;
case 15:
printf("Fifteen\n");
break;
case 16:
printf("Sixteen\n");
break;
case 17:
printf("Seventeen\n");
break;
case 18:
printf("Eighteen\n");
break;
case 19:
printf("Nineteen\n");
break;
default:
switch(num / 10) {
case 2:
printf("Twenty ");
break;
case 3:
printf("Thirty ");
break;
case 4:
printf("Forty ");
break;
case 5:
printf("Fifty ");
break;
case 6:
printf("Sixty ");
break;
case 7:
printf("Seventy ");
break;
case 8:
printf("Eighty ");
break;
case 9:
printf("Ninety ");
break;
}
switch(num % 10) {
case 1:
printf("One\n");
break;
case 2:
printf("Two\n");
break;
case 3:
printf("Three\n");
break;
case 4:
printf("Four\n");
break;
case 5:
printf("Five\n");
break;
case 6:
printf("Six\n");
break;
case 7:
printf("Seven\n");
break;
case 8:
printf("Eight\n");
break;
case 9:
printf("Nine\n");
break;
}
}
return 0;
}
```
Hope this helps!
阅读全文