C语言. 懂的来!!
编写程序,从终端读取一个数字,然后使用英语逐位显示概数.列如,如果用户输入932程序输入:nine three two
这里特别要求,如果用户输入0,那么程序应该显示zero
请大家懂的给个思路或者写出来给大家看看.....
谢谢
参考答案:#include <iostream>
using namespace std;int power(int m);
int main()
{
int shurushu,zhishu=0,zhengchushu,n;
n=power(zhishu);
cout<<"input a number";
cin>>shurushu;
for(;shurushu/n>9;)
{
zhishu++;
n=power(zhishu);
}
for(;zhishu>=0;zhishu--)
{
zhengchushu=shurushu/power(zhishu);shurushu=shurushu%power(zhishu);
switch(zhengchushu)
{
case 0:cout<<"zero ";
break;
case 1:cout<<"one ";
break;
case 2:cout<<"two ";
break;
case 3:cout<<"three ";
break;
case 4:cout<<"four ";
break;
case 5:cout<<"five ";
break;
case 6:cout<<"six ";
break;
case 7:cout<<"seven ";
break;
case 8:cout<<"eight ";
break;
case 9:cout<<"nine ";
break;
}
}
return 0;
}
int power(int m)
{
if(m>0){
int jieguo=10;
for(;m>1;m--)
{
jieguo=jieguo*10;
}
return jieguo;
}
else return 1;
}
思路是一样的,只是这是c++的,差别不大