原来写过一个,但是有BUG,现在贴一个新的 #include <stdlib.h>#include <stdio.h>#include <math.h> int main(void){ double money; char pZH[40]; puts("输入一个数:"); scanf("%lf", &money); double ZH = floor(money); gcvt(ZH, 35, pZH); char *num[10] = {"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"}; char *RMB[] ={"圆","拾","佰","仟","萬","拾","佰","仟","億", "十", "百", "千", "万", "億"}; int n = 0; while (pZH[n] != '.') n++; n--;//输出整数部分 puts("你输入了:"); int flag = 0; int i; for (i=0; pZH[i]!='.'; i++, n--) { if (pZH[i] == '0')//出现多个0时,并非输出所有的"零" {//"亿"和"万"要特殊处理 if (n==8 || n==4 && ((i>=1&&pZH[i-1]!='0')|| (i>=2&&pZH[i-2]!='0')||(i>=3&&pZH[i-3]!='0'))) printf("%s", RMB[n]); flag = 1; continue; } if (flag == 1) printf("零"); printf("%s%s", num[pZH[i]-'0'], RMB[n]); flag = 0; }//输出小数部分 char *unit[4] = {"角", "分", "厘", "毫"}; char pXH[6]; double XH = floor((money-ZH)*10000) ;//不四舍五入了,让银行吃点亏 gcvt(XH, 6, pXH); for (i=0; i<4; i++) printf("%s%s", num[pXH[i]-'0'], unit[i]); printf("\n"); system("pause"); return 0;}

评论