用C语言写以下程序:输入一个整数,输出每个数字对应的拼音。当整数为负数时,先输出fu字。
时间: 2023-09-03 22:15:50 浏览: 151
```c
#include <stdio.h>
int main()
{
int num;
scanf("%d", &num); // 输入整数
if(num < 0) // 判断是否为负数
{
printf("fu "); // 输出fu字
num = -num; // 负数转为正数
}
// 数字对应拼音
switch(num / 1000)
{
case 1: printf("yi "); break;
case 2: printf("er "); break;
case 3: printf("san "); break;
case 4: printf("si "); break;
case 5: printf("wu "); break;
case 6: printf("liu "); break;
case 7: printf("qi "); break;
case 8: printf("ba "); break;
case 9: printf("jiu "); break;
}
switch(num / 100 % 10)
{
case 1: printf("yi "); break;
case 2: printf("er "); break;
case 3: printf("san "); break;
case 4: printf("si "); break;
case 5: printf("wu "); break;
case 6: printf("liu "); break;
case 7: printf("qi "); break;
case 8: printf("ba "); break;
case 9: printf("jiu "); break;
}
switch(num / 10 % 10)
{
case 1: printf("yi "); break;
case 2: printf("er "); break;
case 3: printf("san "); break;
case 4: printf("si "); break;
case 5: printf("wu "); break;
case 6: printf("liu "); break;
case 7: printf("qi "); break;
case 8: printf("ba "); break;
case 9: printf("jiu "); break;
}
switch(num % 10)
{
case 1: printf("yi "); break;
case 2: printf("er "); break;
case 3: printf("san "); break;
case 4: printf("si "); break;
case 5: printf("wu "); break;
case 6: printf("liu "); break;
case 7: printf("qi "); break;
case 8: printf("ba "); break;
case 9: printf("jiu "); break;
}
return 0;
}
```
阅读全文