新手,刚刚写了个关于将数字转成英文格式的,感觉很烦,大家是用什么方法做的,是不是这样,用什么方法比较好
//可以翻译九位数字成英文..大家用的是什么方法,说一说#include "stdio.h"
#include "conio.h"
void shut(unsigned long int a); //将个位转成英文
void shuta(unsigned long int a);//十位转成英文
void shuttt(unsigned long int a) ;//十位是一的情况
main()
{ unsigned long int a,b,c=0,d,e,f,a1[10],b1[10];
scanf("%ld",&a);
if(a<20)
{switch(a)
{
case 1:printf("one",a);break;
case 2:printf("two",a);break;
case 3:printf("three",a);break;
case 4:printf("four",a);break;
case 5:printf("five",a);break;
case 6:printf("six",a);break;
case 7:printf("seven",a);break;
case 8:printf("eight",a);break;
case 9:printf("nine",a);break;
case 10:printf("ten",a);break;
case 11:printf("evelteen",a);break;
case 12:printf("twelteen",a);break;
case 13:printf("sefteen",a);break;
case 14:printf("forteen",a);break;
case 15:printf("fifteen",a);break;
case 16:printf("sixteen",a);break;
case 17:printf("seventeen",a);break;
case 18:printf("eighteen",a);break;
case 19:printf("ninteen",a);break;
} }
else
do{ a1[c]=a%10;c++;a=a/10 ; }
while(a>=10);
c=c+1;
if(c==9)
{ shut(a);
printf("-hundred-");
{if(a1[7]==1)
shuttt(a1[6]);
else if(a1[7]==0)
;
else
shuta(a1[7]); }
if(a1[6]==0)
;
else if(a1[7]==1)
;
else
shut(a1[6]);
printf("-milion-");
if(a1[5]==0)
;
else
{shut(a1[5]);
printf("-hundred-");}
{if(a1[4]==1)
shuttt(a1[3]);
else if(a1[4]==0)
;
else
shuta(a1[4]); }
if(a1[3]==0)
;
else if(a1[4]==1)
;
else
{
shut(a1[3]); }
if(a1[5])
printf("-thousand-");
else
{{if(a1[4])
printf("-thousand-");
else
{ if(a1[3])
printf("-thousand-");
else
;} } }
if(a1[2]==0)
;
else
{shut(a1[2]);
printf("-hundred-"); }
if(a1[1]==1)
shuttt(a1[0]);
else if(a1[1]==0)
shut(a1[0]);
else
{shuta(a1[1]);
shut(a1[0]); } }
else if(c==8)
{{ if(a==1)
shuttt(a1[6]);
else
{ shuta(a);
shut(a1[6]); }
printf("-milion-");
if(a1[5]==0)
;
else
{shut(a1[5]);
printf("-hundred-");}
{if(a1[4]==1)
shuttt(a1[3]);
else if(a1[4]==0)
;
else
shuta(a1[4]); }
if(a1[3]==0)
;
else if(a1[4]==1)
;
else
{
shut(a1[3]); }
if(a1[5])
printf("-thousand-");
else
{{if(a1[4])
printf("-thousand-");
else
{ if(a1[3])
printf("-thousand-");
else
;} } }
if(a1[2]==0)
;
else
{shut(a1[2]);
printf("-hundred-"); }
if(a1[1]==1)
shuttt(a1[0]);
else if(a1[1]==0)
shut(a1[0]);
else
{shuta(a1[1]);
shut(a1[0]); } } }
else if(c==7)
{{ shut(a);
printf("-milion-");
if(a1[5]==0)
;
else
{shut(a1[5]);
printf("-hundred-");}
{if(a1[4]==1)
shuttt(a1[3]);
else if(a1[4]==0)
;
else
shuta(a1[4]); }
if(a1[3]==0)
;
else if(a1[4]==1)
;
else
{
shut(a1[3]); }
if(a1[5])
printf("-thousand-");
else
{{if(a1[4])
printf("-thousand-");
else
{ if(a1[3])
printf("-thousand-");
else
;} } }
if(a1[2]==0)
;
else
{shut(a1[2]);
printf("-hundred-"); }
if(a1[1]==1)
shuttt(a1[0]);
else if(a1[1]==0)
shut(a1[0]);
else
{shuta(a1[1]);
shut(a1[0]); } } }
else if(c==6)
{{ shut(a);
printf("-hundred-");
{if(a1[4]==1)
shuttt(a1[3]);
else if(a1[4]==0)
;
else
shuta(a1[4]); }
if(a1[3]==0)
;
else if(a1[4]==1)
;
else
{
shut(a1[3]); }
printf("-thousand-");
if(a1[2]==0)
;
else
{shut(a1[2]);
printf("-hundred-"); }
if(a1[1]==1)
shuttt(a1[0]);
else if(a1[1]==0)
shut(a1[0]);
else
{shuta(a1[1]);
shut(a1[0]); } } }
else if(c==5)
{
if(a==1)
shuttt(a1[3]);
else
{ shuta(a);
shut(a1[3]); }
printf("-thousand-");
if(a1[2]==0)
;
else
{shut(a1[2]);
printf("-hundred-"); }
if(a1[1]==1)
shuttt(a1[0]);
else if(a1[1]==0)
shut(a1[0]);
else
{shuta(a1[1]);
shut(a1[0]); } }
else if(c==4)
{shut(a);
printf("-thousand-");
shut(a1[2]);
printf("-hundred-");
shuta(a1[1]);
shut(a1[0]); }
else if(c==3)
{shut(a);
printf("-hundred-");
{if(a1[1]==1)
shuttt(a1[0]);
else if(a1[1]==0)
shut(a1[0]);
else
{shuta(a1[1]);
shut(a1[0]); }}}
else
{shuta(a);
shut(a1[0]);
}
getch(); }
void shut(unsigned long int a)
{switch(a)
{
case 1:printf("one",a);break;
case 2:printf("two",a);break;
case 3:printf("three",a);break;
case 4:printf("four",a);break;
case 5:printf("five",a);break;
case 6:printf("six",a);break;
case 7:printf("seven",a);break;
case 8:printf("eight",a);break;
case 9:printf("nine",a);break;
default:printf("");} }
void shuta(unsigned long int a)
{switch(a)
{
case 2:printf("twety-",a); break;
case 3:printf("thirty-",a); break;
case 4:printf("forty-",a); break;
case 5:printf("fifty-",a); break;
case 6:printf("sixty-",a); break;
case 7:printf("seventy-",a); break;
case 8:printf("eighty-",a); break;
case 9:printf("ninty-",a); break;
} }
void shuttt(unsigned long int a)
{switch(a)
{ case 0:printf("tennn",a);break;
case 1:printf("evelteennn",a);break;
case 2:printf("twelteennn",a);break;
case 3:printf("sefteennn",a);break;
case 4:printf("fourteennn",a);break;
case 5:printf("fiveteennn",a);break;
case 6:printf("sixteennn",a);break;
case 7:printf("seventeennn",a);break;
case 8:printf("eightteennn",a);break;
case 9:printf("nineteennn",a);break; }}