----------------解决方案--------------------------------------------------------
就是3 9 2
只输出 单词 three nine two是吗?
不存在10位百位的吧?
----------------解决方案--------------------------------------------------------
如果事先不知道输入的位数的话可以这样。
先建立一个链表,存入每个数.
typedef struct record
{
int n;
struct record *next;
}r,*pr;
pr input()
{
pr p,q=NULL;char c;
while((c=getchar())!='\n')
{
p=(pr)malloc(sizeof(r));
p->n=c-'0';
p->next=q;
q=p;
}
return p;
}
再定义一个字符串数组
char *pp[10]={"zero","one","two","three","four","five","six","seven","eight","nine"};
接下来就从链表头开始取出每个节点的数,然后输出这个数对应的数组中的字符串就行了。这个题的难点就是如何存储任意位数的问题。
[此贴子已经被作者于2007-4-17 16:25:20编辑过]
----------------解决方案--------------------------------------------------------
#include <stdio.h>
#include <conio.h>
int exchange(int);
int main(void)
{
int number;
clrscr();
printf("Please input a number:\n");
scanf("%d",&number);
/*For a int-type data in Turboc2.0,
it's value-area is -32768~32767*/
if(number<0) number=-number;
if(number>9999)
{
exchange(number/10000);
exchange((number%10000)/1000);
exchange((number%1000)/100);
exchange((number%100)/10);
exchange(number%10);
}
else if(number>999)
{
exchange(number/1000);
exchange((number%1000)/100);
exchange((number%100)/10);
exchange(number%10);
}
else if(number>99)
{
exchange(number/100);
exchange((number%100)/10);
exchange(number%10);
}
else if(number>9)
{
exchange(number/10);
exchange(number%10);
}
else
exchange(number);
getch();
}
int exchange(int number)
{
if(number==0)
printf("zero ");
else if(number==1)
printf("one ");
else if(number==2)
printf("two ");
else if(number==3)
printf("three ");
else if(number==4)
printf("four ");
else if(number==5)
printf("five ");
else if(number==6)
printf("six ");
else if(number==7)
printf("seven ");
else if(number==8)
printf("eight ");
else if(number==9)
printf("nine ");
}
----------------解决方案--------------------------------------------------------
可以用switch
case 来做
在用一个循环
----------------解决方案--------------------------------------------------------
恩恩!谢谢各位高手
----------------解决方案--------------------------------------------------------
可以用指针变量指向字符串,外层用for语句循环控制字符走向,然后用switch(i) case 0到9,输出"zero","one","two","three","four","five","six","seven","eight","nine".
----------------解决方案--------------------------------------------------------
请问用switch
case 来做怎么编写呢?
----------------解决方案--------------------------------------------------------
#include "stdlib.h"
#include "stdio.h"
#include "string.h"
int main()
{
char str[10];
char *p;
gets(str);
p = str;
for(;*p!='\0';p++)
switch(*p)
{
case '0':printf("zero");break;
case '1':printf("zero");break;
}
printf("%s",p);
system("pause");
}
其他你自己写把,不要什么都依赖别人啊
----------------解决方案--------------------------------------------------------
好的!谢谢您
----------------解决方案--------------------------------------------------------