资源描述:
《C语言成序设计--实现人民币小写金额与大写金额的转换.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、编程实现,输入一个人民币小写金额值,转化为大写金额值输出。先实现基本功能,如输入.90,可以输出“壹佰零拾零万贰仟三佰零拾零元玖角零分”。#includemain(){doubler,y;intx,m,n,j,i,k,flag=0;intstr1[10]={"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};intstr2[14]={"仟","佰","拾","亿","仟","佰","拾","萬","仟","佰","拾","元","角","分"};charstr3[30];printf("请输入金额(
2、范围小于千亿):");scanf("%lf",&r);if(r>=00)printf("输入的数超出范围,请重新输入");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(
3、str3[k]>0){flag=1;n=k;}}for(j=n;j<=13;j++)printf("%s%s",str1[str3[j]],str2[j]);printf("");}2.(拓展题,分值25)编程实现,输入一个人民币小写金额值,转化为大写金额值输出。要求实现完善的功能,如输入.90,应该输出“壹佰万贰仟三佰元零玖角整”。#includemain(){doubler,y;intx,m,n,j,i,k,flag=0;intstr1[10]={"","壹","贰","叁","肆","伍","陆","柒","捌","玖
4、"};intstr2[14]={"仟","佰","拾","亿","仟","佰","拾","萬","仟","佰","拾","元","角","分"};charstr3[30];printf("请输入金额(范围小于千亿):");scanf("%lf",&r);if(r>=00)printf("输入的数超出范围,请重新输入");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[
5、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
6、
7、j==3
8、
9、j==7)printf("%s",str2[j]);}printf("整");printf("");}if(y!=0)/*当有小数时的输出*/{for
10、(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
11、
12、j==3
13、
14、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)print
15、f("%s%s整",str1[str3[12]],str2[12]);if(str3[12]!=0&&str3[13]!=0)printf("%s角%s分整",str1[str3[12]],str1[str3[13]]);printf("");}}