银行常用的打印程序
2008-03-08 12:52:12 来源:WEB开发网核心提示:/*如:输入:25001 输出:贰万 伍仟 零 壹元输入:123.45输出:壹佰 貳拾 叁元 肆角 伍分*/#include<stdio.h>#include<stdlib.h>char *p[10]={"零","一","二",&quo
/*如:
输入:25001 输出:贰万 伍仟 零 壹元 输入:123.45 输出:壹佰 貳拾 叁元 肆角 伍分
*/
#include<stdio.h>
#include<stdlib.h> char *p[10]={"零","一","二","三","四","五","六","七","八","九"}; int In_Save(char a[], char b[]);/*输入并存储数据*/
void PRint_Zh(char a[], int len);/*输出整数部分 */
void Print_X(char a[]);/*输出小数部分 */ int main(void)
{
char Zh_Shu[26], X_Shu[10];
int len;
len=In_Save(Zh_Shu, X_Shu);
Print_Zh(Zh_Shu, len);
Print_X(X_Shu);
system("pause");
return 0;
} int In_Save(char a[], char b[])
{
char ch;
int i, j;
a: puts("输入一个数:");
scanf("%c", &ch);
while(ch != '\n')/*存储整数部分*/
{
i=0;
j=0;
while(ch != '.' && ch >= '0' && ch <= '9')
{
a[i++]=ch;
scanf("%c", &ch);
}
if(ch == '.')/*存储小数部分*/
{
scanf("%c", &ch);
while(ch != '\n' && ch >= '0' && ch <= '9')
{
b[j++]=ch;
scanf("%c", &ch);
}
if(b[4] >= 5)/*四舍五入*/
b[3] += 1;
}
else if(ch == '\n')/*注重没有输入小数的情况*/
;
else/*输入错误(主要指输入非数字符号)可以重试*/
{
puts("输入错误!请重试");
goto a;
}
}
return i;
} void Print_Zh(char a[], int len)
{
int i, j, flag1, flag2, flag3;
flag1=(a[len-6]=='0' && a[len-7]=='0' && a[len-8]=='0');
flag2=(a[len-14]=='0' && a[len-15]=='0' && a[len-16]=='0');
flag3=(a[len-22]=='0' && a[len-23]=='0' && a[len-24]=='0');
printf("你输入了:\n");
for(i=0,j=len; i<len && j>0; i++,j--)
{
if(a[i] == '0' && i != len-1)
{
if((j == 5 && flag1) (j == 13 && flag2) (j == 21 && flag3 ))
; /*不重复读万,如将1000000050误读作一十亿万零五十圆*/
else if((j == 21 && ! flag3 )(j == 5 && ! flag1)(j == 13 && ! flag2))
printf("万"); /*正确的读法应该是一十亿零五十圆*/
else if(j == 9 j == 17 )/*重复读亿*/
printf("亿");
else if(a[i+1] == '0' && i != len-1)/*不重复读零*/
;
else if(a[i+1] != '0' && i != len-1)
printf("零");
else
;
}
else if(a[i] == '0' && i == len-1)
;
else if(a[i] != '0')
{
switch(a[i])/*读入数字*/
{
case '1': printf("%s",p[1]); break;
case '2': printf("%s",p[2]); break;
case '3': printf("%s",p[3]); break;
case '4': printf("%s",p[4]); break;
case '5': printf("%s",p[5]); break;
case '6': printf("%s",p[6]); break;
case '7': printf("%s",p[7]); break;
case '8': printf("%s",p[8]); break;
case '9': printf("%s",p[9]); break;
default: printf("error"); ; break;
}
switch(j)/*读入单位*/
{
case 2: printf("%s","十"); break;
case 3: printf("%s","百"); break;
case 4: printf("%s","千"); break;
case 5: printf("%s","万"); break;
case 6: printf("%s","十"); break;
case 7: printf("%s","百"); break;
case 8: printf("%s","千"); break;
case 9: printf("%s","亿"); break;
case 10: printf("%s","十"); break;
case 11: printf("%s","百"); break;
case 12: printf("%s","千"); break;
case 13: printf("%s","万"); break;
case 14: printf("%s","十"); break;
case 15: printf("%s","百"); break;
case 16: printf("%s","千"); break;
case 17: printf("%s","亿"); break;
case 18: printf("%s","十"); break;
case
输入:25001 输出:贰万 伍仟 零 壹元 输入:123.45 输出:壹佰 貳拾 叁元 肆角 伍分
*/
#include<stdio.h>
#include<stdlib.h> char *p[10]={"零","一","二","三","四","五","六","七","八","九"}; int In_Save(char a[], char b[]);/*输入并存储数据*/
void PRint_Zh(char a[], int len);/*输出整数部分 */
void Print_X(char a[]);/*输出小数部分 */ int main(void)
{
char Zh_Shu[26], X_Shu[10];
int len;
len=In_Save(Zh_Shu, X_Shu);
Print_Zh(Zh_Shu, len);
Print_X(X_Shu);
system("pause");
return 0;
} int In_Save(char a[], char b[])
{
char ch;
int i, j;
a: puts("输入一个数:");
scanf("%c", &ch);
while(ch != '\n')/*存储整数部分*/
{
i=0;
j=0;
while(ch != '.' && ch >= '0' && ch <= '9')
{
a[i++]=ch;
scanf("%c", &ch);
}
if(ch == '.')/*存储小数部分*/
{
scanf("%c", &ch);
while(ch != '\n' && ch >= '0' && ch <= '9')
{
b[j++]=ch;
scanf("%c", &ch);
}
if(b[4] >= 5)/*四舍五入*/
b[3] += 1;
}
else if(ch == '\n')/*注重没有输入小数的情况*/
;
else/*输入错误(主要指输入非数字符号)可以重试*/
{
puts("输入错误!请重试");
goto a;
}
}
return i;
} void Print_Zh(char a[], int len)
{
int i, j, flag1, flag2, flag3;
flag1=(a[len-6]=='0' && a[len-7]=='0' && a[len-8]=='0');
flag2=(a[len-14]=='0' && a[len-15]=='0' && a[len-16]=='0');
flag3=(a[len-22]=='0' && a[len-23]=='0' && a[len-24]=='0');
printf("你输入了:\n");
for(i=0,j=len; i<len && j>0; i++,j--)
{
if(a[i] == '0' && i != len-1)
{
if((j == 5 && flag1) (j == 13 && flag2) (j == 21 && flag3 ))
; /*不重复读万,如将1000000050误读作一十亿万零五十圆*/
else if((j == 21 && ! flag3 )(j == 5 && ! flag1)(j == 13 && ! flag2))
printf("万"); /*正确的读法应该是一十亿零五十圆*/
else if(j == 9 j == 17 )/*重复读亿*/
printf("亿");
else if(a[i+1] == '0' && i != len-1)/*不重复读零*/
;
else if(a[i+1] != '0' && i != len-1)
printf("零");
else
;
}
else if(a[i] == '0' && i == len-1)
;
else if(a[i] != '0')
{
switch(a[i])/*读入数字*/
{
case '1': printf("%s",p[1]); break;
case '2': printf("%s",p[2]); break;
case '3': printf("%s",p[3]); break;
case '4': printf("%s",p[4]); break;
case '5': printf("%s",p[5]); break;
case '6': printf("%s",p[6]); break;
case '7': printf("%s",p[7]); break;
case '8': printf("%s",p[8]); break;
case '9': printf("%s",p[9]); break;
default: printf("error"); ; break;
}
switch(j)/*读入单位*/
{
case 2: printf("%s","十"); break;
case 3: printf("%s","百"); break;
case 4: printf("%s","千"); break;
case 5: printf("%s","万"); break;
case 6: printf("%s","十"); break;
case 7: printf("%s","百"); break;
case 8: printf("%s","千"); break;
case 9: printf("%s","亿"); break;
case 10: printf("%s","十"); break;
case 11: printf("%s","百"); break;
case 12: printf("%s","千"); break;
case 13: printf("%s","万"); break;
case 14: printf("%s","十"); break;
case 15: printf("%s","百"); break;
case 16: printf("%s","千"); break;
case 17: printf("%s","亿"); break;
case 18: printf("%s","十"); break;
case
更多精彩
赞助商链接