龙空技术网

c语言实现-数字翻译器

额度Y 299

前言:

此时同学们对“c语言数字翻译程序”大约比较关心,我们都想要了解一些“c语言数字翻译程序”的相关文章。那么小编在网络上收集了一些有关“c语言数字翻译程序””的相关知识,希望兄弟们能喜欢,兄弟们一起来了解一下吧!

题目要求:

输入一个正整数N,输出它的英文表达。例如:输入1,输出one;输入12,输出twelve;输入135,输出one hundred thirty five…。编写程序实现之。

题目分析:

解决这道题的关键是弄清阿拉伯数字与英文表达的对应关系。

首先数字1~19中每个数都对应一个英文的单词;

#include "stdio.h"char data_1[19][10]={"one","two","three","four",                	"five","six","seven","eight",                	"nine","ten","eleven","twelve",                	"thirteen","forteen","fifteen","sixteen",                	"seventeen","eighteen","ninteen"};char data_2[8][7]={"twenty","thirty","forty","fifty",                 "sixty","seventy","eighty","ninty"};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);}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);}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]);        }}main(){    long N;    printf("Please input a longeger from 0~999999\n");    scanf("%ld",&N);    translation_A(N);    getche();}

运行结果:

运行结果

标签: #c语言数字翻译程序