在c语言环境中,将数字转化为金额的程序怎么写,如将12345转化为一万两千三百四十五,求解
答案:3 悬赏:30 手机版
解决时间 2021-04-26 16:32
- 提问者网友:遁入空寂
- 2021-04-25 17:29
在c语言环境中,将数字转化为金额的程序怎么写,如将12345转化为一万两千三百四十五,求解
最佳答案
- 五星知识达人网友:神的生死簿
- 2021-04-25 17:36
#include
void print(int a);
int main()
{
int a = 12345;
print(a);
return 0;
}
void print(int num)
{
static const char Bit[15][4]={"","十","百","千","万","十","百","千","亿","十","百","千","万","十","百"};
static const char Num[10][4]={"零","一","二","三","四","五","六","七","八","九"};
int numarr[15] = {0};
int *parr = numarr;
int quotient,i,remainder;
for( quotient = num, remainder = 0; quotient > 0; ){
remainder = quotient % 10;
*parr++ = remainder;
quotient /= 10;
};
for( i= parr - numarr - 1; i >= 0;i--)
printf("%s%s",Num[numarr[i]],Bit[i]);
printf("\n");
};
void print(int a);
int main()
{
int a = 12345;
print(a);
return 0;
}
void print(int num)
{
static const char Bit[15][4]={"","十","百","千","万","十","百","千","亿","十","百","千","万","十","百"};
static const char Num[10][4]={"零","一","二","三","四","五","六","七","八","九"};
int numarr[15] = {0};
int *parr = numarr;
int quotient,i,remainder;
for( quotient = num, remainder = 0; quotient > 0; ){
remainder = quotient % 10;
*parr++ = remainder;
quotient /= 10;
};
for( i= parr - numarr - 1; i >= 0;i--)
printf("%s%s",Num[numarr[i]],Bit[i]);
printf("\n");
};
全部回答
- 1楼网友:污到你湿
- 2021-04-25 19:08
来几个计算出他有他有多少位呀追问只要八位数以内,就行
- 2楼网友:北方的南先生
- 2021-04-25 18:33
思路: 分解每位的数,带上权重
#include
#include
#include "string.h"
void convert_num(int n,char* buf)
{
switch(n)
{
case 0:
sprintf(buf,"%s","零");
break;
case 1:
sprintf(buf,"%s","一");
break;
case 2:
sprintf(buf,"%s","二");
break;
case 3:
sprintf(buf,"%s","三");
break;
case 4:
sprintf(buf,"%s","四");
break;
case 5:
sprintf(buf,"%s","五");
break;
case 6:
sprintf(buf,"%s","六");
break;
case 7:
sprintf(buf,"%s","七");
break;
case 8:
sprintf(buf,"%s","八");
break;
case 9:
sprintf(buf,"%s","九");
break;
}
}
void convert(int n,int power,char* buf)
{
char temp[5]={""};
convert_num(n,temp);
switch(power)
{
case 0:
sprintf(buf,"%s",temp);
break;
case 1:
sprintf(buf,"%s十",temp);
break;
case 2:
sprintf(buf,"%s百",temp);
break;
case 3:
sprintf(buf,"%s千",temp);
break;
case 4:
sprintf(buf,"%s万",temp);
break;
case 5:
sprintf(buf,"%s十",temp);
break;
case 6:
sprintf(buf,"%s百",temp);
break;
case 7:
sprintf(buf,"%s千",temp);
break;
}
}
int main(int argc, char *argv[]) {
char c[10]={""};
char v[50]={""};
scanf("%s",c);
int len=strlen(c);
int i,power;
for(i=0;i
char buf[10]={""};
convert(c[i]-'0',len-i-1,buf);
strcat(v,buf);
}
printf(" %s",v);
return 0;
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯