有这样一个题目:输入一个整数,然后将其翻译成英文如:输入45,让其输出:four five 我下面编了一下,有点问题,但不知道问题出在哪?希望哪位指点指点,谢谢!
#include<stdio.h>
main()
{
int a,b,i=0,m[5];
printf("please imput a integer:");
scanf("%d",&a);
m[i]=a%10;
b=a/10;
while(b!=0)
{
m[i+1]=b%10;
b/=10;
i++;
}
while(i>=0)
{
switch(m[i])
{case 0:
printf("zero-t");
break;
case 1:
printf("one-t");
break;
case 2:
printf("two-t");
break;
case 3:
printf("three-t");
break;
case 4:
printf("four-t");
break;
case 5:
printf("five-t");
break;
case 6:
printf("six-t");
break;
case 7:
printf("seven-t");
break;
case 8:
printf("eight-t");
break;
case 9:
printf("nine-t");
break;
}
i--;
}
getch();
}
----------------解决方案--------------------------------------------------------
#include<stdio.h>
int main()
{
long num;
int a[10],i=0;
scanf("%ld",&num);
while(num)
{
a[i]=num%10;
i++;
num/=10;
}
while(--i>=0)
{
switch(a[i])
{
case 0:
printf("zero-t");
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;
}
}
printf("\n");
getch();
return(0);
}
----------------解决方案--------------------------------------------------------
谢谢版主~~
----------------解决方案--------------------------------------------------------
#include<stdio.h>
int main()
{
long num;
int a[10],i=0;
scanf("%ld",&num);
while(num)
{
a[i]=num%10;
i++;
num/=10;
}
while(--i>=0)
{
switch(a[i])
{
case 0:
printf("zero-t");
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;
}
}
printf("\n");
getch();
return(0);
}
那个-t是干什么用的啊?
----------------解决方案--------------------------------------------------------
呵呵,忘了删掉了.
我也不知道,可能上楼主要的什么格式吧.
----------------解决方案--------------------------------------------------------
#include <stdio.h>
int main()
{
long num;
int a[10],i=0;
scanf("%ld",&num);
while(num)
{
a[i]=num%10;
i++;
num/=10;
}
char *pBuf[]={"zero ",
"one ",
"two ",
"three ",
"four ",
"five ",
"six ",
"seven ",
"eight ",
"nine"};
while(--i>=0)
{
printf("%s",pBuf[a[i]]);
}
return 0;
}
[此贴子已经被作者于2006-10-15 12:39:16编辑过]
----------------解决方案--------------------------------------------------------
支持六楼
----------------解决方案--------------------------------------------------------