编写自定义函数

来源:百度知道 编辑:UC知道 时间:2024/05/14 13:03:20
能将错就错100以内的人民币数字转换为大写

const char * RMB(int a)
{
char rmbdx[20];
char *DX[] = {"零","壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"};
int s = 0, g = 0;
if(a < 100)
{
s = a / 10;
g = a % 10;
if(s > 0)
{
strcpy(rmbdx, dx[s]);
strcat(rmbdx, "拾");
if(g > 0)
{
strcat(rmbdx, dx[g]);
}
strcat(rmbdx, "元");
return rmbdx;
}
else
{
if(g > 0)
{
strcat(rmbdx, dx[g]);
strcat(rmbdx, "元");
return rmbdx;
}
}
}
return NULL;
}