2016我是歌手全体名单:C语言求助~

来源:百度文库 编辑:高校问答 时间:2024/05/10 18:35:31
求助: 从终端读取一个数字,然后用英文显示该数,
如输入932 显示:nine three two
不用数组,指针怎么做?(用switch,while do等)

我来给弄全吧。
#include "stdio.h"
main()
{
char ch;
while ((ch = getchar()) != '\n') {
switch(ch) {
case '0': printf("zero"); break;
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;
default: break;
}
}
getch();

}

char ch;
while ((ch = getchar()) != '\n') {
switch(ch) {
case '0': printf("zero"); break;
case '1': printf("one"); break;
......
default: break;
}
}

就是这个意思了
循环读取字符, 遇到回车结束

自己写写吧

1、声明一个长为10的字符串数组str,存放0-9的英文单词
2、读取数字后,用itoa转成字符串
3、用一个字符指针p指向该字符串,向后遍历,依次输出str[*p-'0']

我想请问一下二楼 “ itoa转换成字符串”是啥意思啊。。请赐教,谢谢。

楼上答案不错