C语言-数字翻译器

Posted 灯火阑处

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C语言-数字翻译器相关的知识,希望对你有一定的参考价值。

输入一个正整数N,输出它的英文表达

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][8]   = "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eight", "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);
    printf("\\n");

int main(int argc, const char *argv[]) 
    long N;
    printf("Please input a longeger from 0~999999\\n");
    scanf("%ld", &N);
    translation_A(N);
    
    return 0;

结果:

以上是关于C语言-数字翻译器的主要内容,如果未能解决你的问题,请参考以下文章

c语言 怎么判断输入的是否数字?

c语言 如何判断输入的是数字还是字母

C语言 一个int型到底可以表示多大的数字?

C Model和编译器的关系

c语言中对较大数字的处理?

C语言初学,求任意四位数字个十百千位的和。老是提示指示符错误