作业帮 > 综合 > 作业

谁能帮小弟解答一道C语言题目 小弟是菜鸟

来源:学生作业帮 编辑:搜狗做题网作业帮 分类:综合作业 时间:2024/08/15 01:15:54
谁能帮小弟解答一道C语言题目 小弟是菜鸟
Write a program that takes an integer keyed in from the terminal and extracts and displays each digit of the integer in English.So,if the user types in 932,the program should display:
nine three two
Remember to display "zero" if the user types in just a 0.
This exercise is non simple,so make sure that you have worked out your algorithm in advance.
谁能帮小弟解答一道C语言题目 小弟是菜鸟
首先要建立数字0-9和英文”zero“-”nine“的对应关系
然后,一个int数组,存放输入的int的各个数字
然后用输入的那个int不停的除以10,取余,结果放进数组里,再除以10……
直到输入的int为0.另外输入为0的单独处理
依次从数组末尾取出数字转换成鸟文输出到屏幕上

偷懒的方法就是输入的时候你不存成一个int,而直接存在数组里……
再问: 能把程序写给我看吗 我是菜鸟 拜托了
再答: 好吧,你等等…… sun_siliang,题目说 takes AN INTEGER keyed in from the terminal 我的理解是”从终端读取的输入存到一个整型变量里“…… 如果一开始就一个个读,这题就没什么难度 //以下是程序代码 #include int main() { char num[][10]={"zero","one","two","three","four","five","six","seven","eight","nine"}; int input,a[20],index; //假设输入都在一个int变量的表达范围内 scanf("%d",&input); if (input) //如果input不为0 { index=0; while(input) { a[index]=input%10; input=input/10; ++index; } } else //单独处理输入为0的情况 { printf("zero\n"); } while(index>0) { --index; printf("%s",num[a[index]]); if (index) //这里是为了符合题目要求的输出格式…… { printf(" "); } } return 0; }