u011021736 于 2013.06.10 11:21 提问

1个回答

qq_27976105   2016.12.03 15:35

`````` /*把钱数转换为大写金额*/
#include "stdio.h"
void ChangeDaXiaoXie(char c);
void ChaiFen(int value);
void Chaifen(float fact);
void PrintDanWei(int n);
char string[25];
void main()
{
float shu = 0;
int value = 0;float fact=0.0;
printf("请输入人民币金额:");
scanf("%f", &shu);
value = (int)shu;
fact = shu - value;
ChaiFen(value);
Chaifen(fact);
}
void ChaiFen(int value)
{   int i=0;
int fuben=value;
int n=0;
while(fuben)
{
string[n]=fuben%10;
fuben=fuben/10;
n++;
}

for(i=n-1;i+1>0;i--)
{
ChangeDaXiaoXie(string[i]);
PrintDanWei(i);
}
}
void PrintDanWei(int n)
{
if(n>4 &&n<9)
{
n=n-4;
}
switch(n){
case -3:
printf("厘");
break;
case -2:
printf("分");
break;
case -1:
printf("角");
break;
case 0:
printf("圆");
break;
case 1:
printf("拾");
break;
case 2:
printf("佰");
break;
case 3:
printf("千");
break;
case 4:
printf("萬");
break;
case 5:

break;
default:
break;}

}

void ChangeDaXiaoXie(char c)
{
switch(c)
{
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;
}
}

void Chaifen(float fact)
{
float fuben=fact;
int m;
int i=0;
for(i=-1;i+4>0;i--)
{
fuben=fuben*10.0;
m=(int)fuben%10;

ChangeDaXiaoXie(m);
PrintDanWei(i);
}
}

``````