| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1764 人关注过本帖
标题:新手,刚刚写了个关于将数字转成英文格式的,感觉很烦,大家是用什么方法做的, ...
取消只看楼主 加入收藏
忘了
Rank: 2
等 级:论坛游民
帖 子:16
专家分:55
注 册:2010-5-17
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:0 
新手,刚刚写了个关于将数字转成英文格式的,感觉很烦,大家是用什么方法做的,是不是这样,用什么方法比较好
//可以翻译九位数字成英文..大家用的是什么方法,说一说
#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; }}
搜索更多相关主题的帖子: 成英文 数字 格式 感觉 
2010-05-17 13:40
快速回复:新手,刚刚写了个关于将数字转成英文格式的,感觉很烦,大家是用什么方法 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024498 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved