简介:将输入的含有小数位的金额转换为大写金额输出
反思:
1>注意每一位的输出含义
2>可以通过多种情况枚举推演计算公式
以下为代码实现
#include <stdio.h>
#include <string.h>
int main()
{
int i, t;
char st[24];
printf("请输入金额:");
scanf("%s",st);
t = 0;
for(i=0; st[i]!='\0'; i++)
{
if(st[i]=='.')
break;
t++;
}
int j;
for(i=0; st[i]!='\0'; i++)
{
j = (12-t)+i;
if(st[i] == '0')
printf("零");
else if(st[i] == '1')
printf("壹");
else if(st[i] == '2')
printf("贰");
else if(st[i] == '3')
printf("叁");
else if(st[i] == '4')
printf("肆");
else if(st[i] == '5')
printf("伍");
else if(st[i] == '6')
printf("陆");
else if(st[i] == '7')
printf("柒");
else if(st[i] == '8')
printf("捌");
else if(st[i] == '9')
printf("玖");
if(j == 0)
printf("仟");
else if(j == 1)
printf("佰");
else if(j == 2)
printf("拾");
else if(j == 3)
printf("亿");
else if(j == 4)
printf("仟");
else if(j == 5)
printf("佰");
else if(j == 6)
printf("拾");
else if(j == 7)
printf("万");
else if(j == 8)
printf("仟");
else if(j == 9)
printf("佰");
else if(j == 10)
printf("拾");
else if(j == 11)
printf("元");
else if(j == 13)
printf("角");
else if(j == 14)
printf("分");
}
printf("整");
printf("\n");
return 0;
}