Q:输入一个数,输出英文表达。

 

 

#include"stdio.h"
char data_1[19][10]={"0ne","two","three","four","five","six","seven","eight","nine","ten"
					,"eleven","twelve","thirteen","forteen","fifteen","sixteen","seventeen",
					"eighteen","ninteen"};

char data_2[8][9]={"twenty","thirty","forty","fifty","sixty","seventy","eighty","ninty"};

void translation_C(long b) {	//翻译十位与个位 
	long c;
	if(b<=19)	printf("%s ",data_1[b-1]);
	else {
		c=b/10;
		printf("%s ",data_2[c-2]);
		c=b%10;
		if(c!=0)	printf("%s ",data_1[c-1]);	
	}
}

void translation_B(long a) {	//翻译百位 
	long b;
	b=a/100;
	if(b!=0) {
		translation_C(b);
		printf("hundred ");
	}
	b=a%100;
	if(b!=0)
		translation_C(b);
} 

void translation_A(long N) {	//翻译千位 
	long a;
	if(N==0) {
		printf("Zero\n");
		return ;
	}
	a=N/1000;
	if(a!=0) {
		translation_B(a);
		printf("thousand ");
	}
	a=N%1000;
	if(a!=0)
		translation_B(a);
} 
	
int main() {
	long N;
	printf("input a longeger from 0~999999\n ");
	scanf("%ld",&N);
	translation_A(N);
	return 0;
}

  

posted on 2017-05-04 13:22  王小东大将军  阅读(148)  评论(0编辑  收藏  举报