当前位置: 代码迷 >> C语言 >> [求助]关于大小写数字的转换,请高手指点
  详细解决方案

[求助]关于大小写数字的转换,请高手指点

热度:138   发布时间:2007-04-12 15:04:25.0
[求助]关于大小写数字的转换,请高手指点
请大家帮忙看看 小数点后面为什么会出现问题(小数点后面应该是数组b2里面的内容,可输出时却有数组b1里面的内容)谢谢

#include<stdio.h>
void main()
{
char grade[50];
int i,point;
char *b1[9]={"亿","千","百","十","万","千","百","十","元"};
//char *b1[9]={"元","十","百","千","万","十","百","千","亿"};
char *b2[3]={"角","分","厘"};
//do
//{
printf("请输入金额:");
gets(grade);
//for(i=0;i<50;i++)
//{
//if(grade[i]!='.')
//{
//printf("请输入一个带有小数点的金额!\n");
//break;
//}
//}
//}while(grade[i]!='.');
for(i=0;i<50;i++)
{
if(grade[i]=='.')
{
point=i;
break;
}
}
for(i=0;i<50;i++)
{
if(i<point)
{
switch(grade[i])
{
case '0':
printf("零");
break;
case '1':
printf("壹");
break;
case '2':
printf("贰");
break;
case '3':
printf("叁");
break;
case '4':
printf("肆");
break;
case '5':
printf("伍");
break;
case '6':
printf("陆");
break;
case '7':
printf("柒");
break;
case '8':
printf("捌");
break;
case '9':
printf("玖");
break;
}
printf("%s",b1[i+(9-point)]);
}
}
for(i=0;i<50;i++)
{
if(i>point)
{
switch(grade[i])
{
case '0':
printf("零");
break;
case '1':
printf("壹");
break;
case '2':
printf("贰");
break;
case '3':
printf("叁");
break;
case '4':
printf("肆");
break;
case '5':
printf("伍");
break;
case '6':
printf("陆");
break;
case '7':
printf("柒");
break;
case '8':
printf("捌");
break;
case '9':
printf("玖");
break;
}
printf("%s",b2[i]);
}
}
}
搜索更多相关的解决方案: 数字  大小写  

----------------解决方案--------------------------------------------------------
以下是引用非凡DZ在2007-4-12 15:04:25的发言:
请大家帮忙看看 小数点后面为什么会出现问题(小数点后面应该是数组b2里面的内容,可输出时却有数组b1里面的内容)谢谢

#include<stdio.h>
void main()
{
char grade[50];
int i,point;
char *b1[9]={"亿","千","百","十","万","千","百","十","元"};
//char *b1[9]={"元","十","百","千","万","十","百","千","亿"};
char *b2[3]={"角","分","厘"};
//do
//{
printf("请输入金额:");
gets(grade);
//for(i=0;i<50;i++)
//{
//if(grade[i]!='.')
//{
//printf("请输入一个带有小数点的金额!\n");
//break;
//}
//}
//}while(grade[i]!='.');
for(i=0;i<50;i++)
{
if(grade[i]=='.')
{
point=i;
break;
}
}
for(i=0;i<50;i++)
{
if(i<point)
{
switch(grade[i])
{
case '0':
printf("零");
break;
case '1':
printf("壹");
break;
case '2':
printf("贰");
break;
case '3':
printf("叁");
break;
case '4':
printf("肆");
break;
case '5':
printf("伍");
break;
case '6':
printf("陆");
break;
case '7':
printf("柒");
break;
case '8':
printf("捌");
break;
case '9':
printf("玖");
break;
}
printf("%s",b1[i+(9-point)]);
}
}
for(i=0;i<50;i++)
{
if(i>point)
{
switch(grade[i])
{
case '0':
printf("零");
break;
case '1':
printf("壹");
break;
case '2':
printf("贰");
break;
case '3':
printf("叁");
break;
case '4':
printf("肆");
break;
case '5':
printf("伍");
break;
case '6':
printf("陆");
break;
case '7':
printf("柒");
break;
case '8':
printf("捌");
break;
case '9':
printf("玖");
break;
}
printf("%s",b2[i]); //数组越界...
}
}
}


----------------解决方案--------------------------------------------------------

  相关解决方案