有没有大神帮忙 看看怎么回事呀??
#include<stdio.h>voidtran(inta,inti);intmain(){floata;intb;printf("请输入一行数字:\n");scanf...
#include <stdio.h>
void tran(int a,int i);
int main()
{
float a;
int b;
printf("请输入一行数字:\n");
scanf("%f",&a);
b=a*100;
tran(b,0);
return 0;
}
void tran(int a,int i)
{
int j;
char num[][3]={"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
char hx[][3]={"","分","角","元","拾","佰","仟","万","拾","佰","仟","亿"};
if(a!=0) { j=a%10;i++;tran((a/=10),i);}
printf("%s%s",num[j],hx[i]);
} 展开
void tran(int a,int i);
int main()
{
float a;
int b;
printf("请输入一行数字:\n");
scanf("%f",&a);
b=a*100;
tran(b,0);
return 0;
}
void tran(int a,int i)
{
int j;
char num[][3]={"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
char hx[][3]={"","分","角","元","拾","佰","仟","万","拾","佰","仟","亿"};
if(a!=0) { j=a%10;i++;tran((a/=10),i);}
printf("%s%s",num[j],hx[i]);
} 展开
展开全部
不是这么简单的,中文大写还要解决多个0的问题,例如10008读“壹万零捌”,这里有各种语言的代码:
http://hi.baidu.com/134931/item/d8c544531ccbf4948c12ed32
C语言这样写:
main(){
int i,j;
double x;
char xxx[80],rmb_up_char[80],tmp[80];
char *rmb_unit[]={"仟","佰","拾","亿","仟","佰","拾", "万","仟","佰","拾","元","角","分"};
char *num_up_char[]={"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
printf("输入小写数字:");
scanf("%lf",&x);
if (x==0) strcpy(rmb_up_char,"零");
else{
sprintf(xxx,"%015.0lf", x*100);
/*puts(xxx);*/
rmb_up_char[0]='\0';
tmp[0] = '\0';
i=0;
while (i<15 && xxx[i]=='0') i++;
while (i<15){
if (xxx[i]!='0'){
j=xxx[i]-'0';
strcat(rmb_up_char, tmp);
strcat(rmb_up_char, num_up_char[j]);
strcat(rmb_up_char, rmb_unit[i-1]);
tmp[0] = '\0';
}else{
strcpy(tmp, num_up_char[0]);
if ((i==4 || i==8) && (xxx[i-3]!='0' || xxx[i-2]!='0' || xxx[i-1]!='0' || xxx[i]!='0')) strcat(rmb_up_char,rmb_unit[i-1]);
if (i==12) strcat(rmb_up_char,"元");
}
i++;
}
}
puts(rmb_up_char);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询