用C语言Write a program that asks the user for a two-digit number, then prints the English word for the number:
时间: 2023-05-11 09:02:18 浏览: 155
Sure, here's the code:
```
#include <stdio.h>
int main() {
int num;
printf("Please enter a two-digit number: ");
scanf("%d", &num);
int tens = num / 10;
int ones = num % 10;
switch (tens) {
case 1:
switch (ones) {
case 0:
printf("ten");
break;
case 1:
printf("eleven");
break;
case 2:
printf("twelve");
break;
case 3:
printf("thirteen");
break;
case 4:
printf("fourteen");
break;
case 5:
printf("fifteen");
break;
case 6:
printf("sixteen");
break;
case 7:
printf("seventeen");
break;
case 8:
printf("eighteen");
break;
case 9:
printf("nineteen");
break;
}
break;
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;
}
if (tens != 1) {
switch (ones) {
case 1:
printf("one");
break;
case 2:
printf("two");
break;
case 3:
printf("three");
break;
case 4:
printf("four");
break;
case 5:
printf("five");
break;
case 6:
printf("six");
break;
case 7:
printf("seven");
break;
case 8:
printf("eight");
break;
case 9:
printf("nine");
break;
}
}
printf("\n");
return 0;
}
```
This program asks the user for a two-digit number and then prints the English word for the number. For example, if the user enters 42, the program will output "forty-two".
阅读全文