C语言成序设计 实现人民币小写金额与大写金额的转换

2022-05-27 20:10:15   文档大全网     [ 字体: ] [ 阅读: ]

#文档大全网# 导语】以下是®文档大全网的小编为您整理的《C语言成序设计 实现人民币小写金额与大写金额的转换》,欢迎阅读!
金额,小写,大写,转换,人民币
编程实现,输入一个人民币小写金额值,转化为大写金额值输出。先实现基本功能,如输入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.wddqxz.cn/46324df8fab069dc5022015b.html

相关推荐