#include <stdio.h>
#include <string.h>
char *ones[20]={"零","壹","贰","叁","肆","伍","陆","柒","捌","玖","拾"};
char *units[5]={"","万"};
//转换角分,如:36 三角六分
char* NumZeros(char cn[], unsigned short num)
{
unsigned short bit; /*~~*/
if (bit=num/10)
{
strcat(cn, ones[bit]);
strcat(cn, "角");
}
if (bit=num%10)
{
strcat(cn, ones[bit]);
strcat(cn, "分");
}
return cn;
}
//转换4位数
//参数1:存放大写的char[],参数2:需要转换的数(小于10000),参数三:单独用时用0
char* Num4Bit(char cn[], unsigned short num, int* NodeH)
{
unsigned short Node3=0, Node2=0, Node1=0;
unsigned short bit;
if (bit=num/1000)
{
strcat(cn, ones[bit]);
strcat(cn, "仟");
Node3=1;
}
if (bit=num/100%10)
{
if (!Node3 && *NodeH) strcat(cn, "零");
strcat(cn, ones[bit]);
strcat(cn, "佰");
Node2=1;
}
if (bit=num/10%10)
{
if (!Node2 && (*NodeH || Node3)) strcat(cn, "零");
strcat(cn, ones[bit]);
strcat(cn, "拾");
Node1=1;
}
if (bit=num%10)
{
if (!Node1 && (*NodeH || Node3 || Node2)) strcat(cn, "零");
strcat(cn, ones[bit]);
}
if (num>0) *NodeH=1;
return cn;
}
//参数1:存放大写的char[],参数2:需要转换的数(最大2^64-1即unsigned long最大值)
char* NumToCn(char cn[], unsigned long num)
{
char NumZero[9]={'\0'}, FlagZ[3]={0,0,0};
unsigned long i,bit,j;
int NodeH=0, HaveZ=0;
if (num==0) return strcat(cn, "零园整");
NumZeros(NumZero, num%100);
for (i=1e6, j=1; i>=100; i/=10000, j--)
{
if (bit=(num/i)%10000)
{
//防止多级为0而打印多个“零”
if (NodeH && FlagZ[j+1]==1 && !HaveZ)
{
strcat(cn, "零");
HaveZ=1;
NodeH=0;
}
Num4Bit(cn, bit, &NodeH);
strcat(cn, units[j]);
HaveZ=0;
}
else FlagZ[j]=1; //某一级数为0,则设置标志
}
if (num>=100) strcat(cn, NumZero[0]=='\0'?"圆整":"圆");
return strcat(cn, NumZero);
}
void main()
{
char cn[81];
unsigned long num;
printf("人民币小写转大写\n倒数第三位为元\n比如:1234指12.34元\n");
while(1)
{
printf("金额:");
scanf("%d", &num);
cn[0]='\0';
printf("%s\n", NumToCn(cn, num));
}
}
初学者 又要用到这个程序 帮我做个详细的注释 顺便在你们的机子上面跑跑吧 看看 有没什么错误 检查下
我需要的每一行的注释
不是广泛的笼统的说下这是什么
只要每一行后面做个注释就好了