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语言-数字翻译器的主要内容,如果未能解决你的问题,请参考以下文章