c语言 数字变大写 代码

Modified on: Sun, 28 Oct 2018 11:29:00 +0800 热度: 1,474 度

#include <stdio.h>
#include <string.h>
char* unit(int);

int main(int argc, const char * argv[])
{

long long  num;
int  nums[15];
char upper[10][4]={"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
int  count=0;
int  i=0;
char re[200];

printf("请输入小写的数字:");
scanf("%lld",&num);
while(num!=0)
{
    nums[i]=num%10;
    num /=10;
    i++;
    count++;
}
if (count>15)
{
    printf("输入的数字过大,无法处理.\n");
    return 0;
}
printf("\n");
for (i=0;i<count;i++)
{
    printf("nums[%d]的值为:%d,对应的大写字母为:%s\n",i,nums[i],upper[nums[i]]);
}
printf("\n\n");

for (i=count-1;i>=0;i--)
{
    strcat(re,upper[nums[i]]);
    strcat(re,unit(i));
}
printf("得到的值为:%s\n",re);
return 0;

}
char* unit(int count)
{

switch (count)
{
    case 0:
        return "";
    case 1:
        return "拾";
    case 2:
        return "佰";
    case 3:
        return "仟";
    case 4:
        return "万";
    case 5:
        return "拾";
    case 6:
        return "佰";
    case 7:
        return "仟";
    case 8:
        return "亿";
    case 9:
        return "拾";
    case 10:
        return "佰";
    case 11:
        return "仟";
    case 12:
        return "兆";
    case 13:
        return "拾";
    case 14:
        return "佰";
    case 15:
        return "仟";
        
}
return 0;

}

添加新评论