小白有个问题,希望各位给个思路,直接要代码答案太不好啦
就是要求输入一个数字,比如输入123,输出一百二十三,输入1234,则输出一千二百三十四,等,求大家给点小思路哇,有福利
#include<stdio.h> int main() { int n,a[10],i,m=0,p; char str1[10][3]={"零","一","二","三","四","五","六","七","八","九"}; char str2[5][5]={"十","百","千","万"}; printf("输入数字:"); scanf("%d",&n); for(i=0;i<10;i++) { a[i]=n%10; n=n/10; m++; if(n==0)break; } if(m>1) for(i=m-1;i>0;i--) { if(a[i]!=0) { p=a[i]; printf("%s%s",str1[p],str2[(i-1)%4]); } else if(i==4&&a[i]==0) printf("万"); else if(a[i-1]!=0) printf("零"); else continue; } p=a[0]; if(p!=0) printf("%s\n",str1[p]); else printf(" "); return 0; }
[此贴子已经被作者于2017-10-11 16:03编辑过]