C语言编程 从键盘输入一个小于1000的正整数,并读入该值,然后输出用语言描述的该整数值。例如,9

C语言编程 从键盘输入一个小于1000的正整数,并读入该值,然后输出用语言描述的该整数值。例如,941,程序将输出
字符串"Nine hundred and forty one."

#include <stdlib.h>
#include <stdio.h>
using namespace std;

int n;

int main()
{
scanf("%d", &n);
int v = n/100;
 if (v == 9) printf("Nine hundred");
else if (v == 8) printf("Eight hundred");
else if (v == 7) printf("Seven hundred");
else if (v == 6) printf("Six hundred");
else if (v == 5) printf("Five hundred");
else if (v == 4) printf("Four hundred");
else if (v == 3) printf("Three hundred");
else if (v == 2) printf("Two hundred");
else if (v == 1) printf("One hundred");

if (!(n%100))
{
printf(".\n");
return 0;
}

printf(" and ");

v = (n/10)%10;
 if (v == 9) printf("ninety ");
else if (v == 8) printf("eighty ");
else if (v == 7) printf("seventy ");
else if (v == 6) printf("sixty ");
else if (v == 5) printf("fifty ");
else if (v == 4) printf("forty ");
else if (v == 3) printf("thirty ");
else if (v == 2) printf("twenty ");
if (v == 1)
{
v = n%10;
 if (v == 9) printf("nineteen");
else if (v == 8) printf("eighteen");
else if (v == 7) printf("seventeen");
else if (v == 6) printf("sixteen");
else if (v == 5) printf("fifteen");
else if (v == 4) printf("fourteen");
else if (v == 3) printf("thirteen");
else if (v == 2) printf("twelve");
else if (v == 1) printf("eleven");
else if (v == 0) printf("ten");
}

if ((n/10)%10 != 1)
{
v = n%10;
 if (v == 9) printf("nine");
else if (v == 8) printf("eight");
else if (v == 7) printf("seven");
else if (v == 6) printf("six");
else if (v == 5) printf("five");
else if (v == 4) printf("four");
else if (v == 3) printf("three");
else if (v == 2) printf("two");
else if (v == 1) printf("one");
}

printf(".\n");
return 0;
}

幸苦打的,望采纳

追问

谢谢你

追答

不用谢

追问

哥,10位是1的时候,
是这样表示么,,

比如,214
应该是 Two hundred and fourteen. 吧

哥.....在嘛……

追答

我的程序没有错呀。我测试过214的

另外,我交给你的代码曾经修改过一次,你看看是不是拿了我修改前的代码了。

追问

呀,对了⊙▽⊙
谢谢了,
话说您用的什么软件这是?

追答

DevC++ 5.9.2

这玩意这不是这么好找的哦!有点贵。

追问

好嘛好嘛,,
谢谢咯,
新年快乐~

追答

……谢谢

温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-02-17
使用除10取余数的方法即可。追问

能帮我做个代码出来吗?
这题没那么简单

追答

年前很忙,给你个思路。例如941,首先对100取余,为9,输出nine hundred and,如对100取余为0则不输出。将将941-9*100,为41,继续对10取余为4,输出forty,减去4*10后输出one,以上输出的内容可定义3个字符串数组,保存输出结果的百,十,个位,保存如“nine hundred and”,"forty","one"等形式,根据取余结果进行输出。

追问

谢谢您~
新年快乐~

相似回答