编程实现,输入一个人民币小写金额值,转化为大写金额值输出。先实现基本功能,如输入1002300.90,可以输出“壹佰零拾零万贰仟三佰零拾零元玖角零分”。 # include main() {double r,y; int x, m,n,j,i,k,flag=0; int str1[10]={"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"}; int str2[14]={"仟","佰","拾","亿","仟","佰","拾","萬","仟","佰","拾","元","角","分"}; char str3[30]; printf("请输入金额(范围小于千亿):\n"); scanf("%lf",&r); if(r>=1000000000000) printf("输入的数超出范围,请重新输入\n"); y=r-(int)r; /*y为小数部分*/ x=(int)r; /*x为整数部分*/ for(i=0;i<=11;i++) /*整数部分*/ { m=(int)((int)x%10); str3[11-i]=m; x=(int)(x/10); } str3[12]=(int)(y*10); /*小数部分*/ str3[13]=(int)(y*100)%10; for(k=0;k<=13&&flag==0;k++) /*判断最大位是多少*/ {if(str3[k]>0) {flag=1;n=k; } } for(j=n;j<=13;j++) printf("%s%s",str1[str3[j]],str2[j]); printf("\n"); } 2.(拓展题,分值25)编程实现,输入一个人民币小写金额值,转化为大写金额值输出。要求实现完善的功能,如输入1002300.90,应该输出“壹佰万贰仟三佰元零玖角整”。 # include main() {double r,y; int x, m,n,j,i,k,flag=0; int str1[10]={"","壹","贰","叁","肆","伍","陆","柒","捌","玖"}; int str2[14]={"仟","佰","拾","亿","仟","佰","拾","萬","仟","佰","拾","元","角","分"}; char str3[30]; printf("请输入金额(范围小于千亿):\n"); scanf("%lf",&r); if(r>=1000000000000) printf("输入的数超出范围,请重新输入\n"); y=r-(int)r; /*y为小数部分*/ x=(int)r; /*x为整数部分*/ for(i=0;i<=11;i++) { m=(int)((int)x%10); str3[11-i]=m; x=(int)(x/10); } str3[12]=(int)(y*10); str3[13]=(int)(y*100)%10; if(y==0) /*当没有小数时的输出*/ {for(k=0;k<=13&&flag==0;k++) /*判断最大位是多少*/ {if(str3[k]>0) {flag=1;n=k; } } for(j=n;j<=11;j++) {printf("%s",str1[str3[j]]); if(str3[j]!=0||j==3||j==7) printf("%s",str2[j]); } printf("整\n"); printf("\n"); } if(y!=0) /*当有小数时的输出*/ {for(k=0;k<=13&&flag==0;k++) /*先输出整数*/ {if(str3[k]>0) {flag=1;n=k; } } for(j=n;j<=11;j++) {printf("%s",str1[str3[j]]); if(str3[j]!=0||j==3||j==7) printf("%s",str2[j]); } printf("零"); if(str3[12]==0&&str3[13]!=0) /*输出小数*/ printf("%s%s整",str1[str3[13]],str2[13]); if(str3[12]!=0&&str3[13]==0) printf("%s%s整",str1[str3[12]],str2[12]); if(str3[12]!=0&&str3[13]!=0) printf("%s角%s分整",str1[str3[12]],str1[str3[13]]); printf("\n"); } } 本文来源:https://www.wddqw.com/doc/46324df8fab069dc5022015b.html