本文主要是介绍一道笔试题 - 数字转大写金额,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
要求:将输入的数字转换成大写的金额形式。如:
1、123转为壹佰贰拾叁圆
2、2003转为贰仟零叁圆
3、20000转为贰万圆
#include <stdio.h>
#define M 100
void exchange(char *name[],int ver,int array[],char *mname[])
{ int i=0,k,temp,iszero=0;temp=ver;printf("\n");while(i<ver){ k=array[i];if(k==0){if(iszero == 0 && array[i+1] != 0 && i+1 < ver){iszero = 1;printf("%s",name[k]);}if(temp==5){printf("%s",mname[temp-1]);}if(temp==1){printf("%s",mname[temp-1]);}}else{iszero = 0;printf("%s%s",name[k],mname[temp-1]);}temp--;i++;}
}
int input(int *po,int *p)
{ int loop=0,pp;printf("\n请输入金额\n");scanf("%d",po);pp=*po;while(pp>=1){*p=pp%10;p++;pp=pp/10;loop++;}return loop;
}
void inv(int *pointer,int ver)
{int temp,*po,i=0,m,*p,*pp;m=(ver-1)/2;p=pointer;po=pointer+ver-1;pp=pointer+m;for(;p<=pp;p++,po--){temp=*p;*p=*po;*po=temp;}
}
void main()
{char * name[]={"零","壹","贰","叁","肆","伍","陆","柒","扒","玖","拾"};char *mname[]={"圆","十","百","千","万","十","百","千","亿"};int n,money,array[M],ver;ver=input(&money,array);inv(array,ver);printf("%d,%d",money,ver);exchange(name,ver,array,mname);
}
这篇关于一道笔试题 - 数字转大写金额的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!