正文

银行常用的打印程序2005-03-28 08:30:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/goal00001111/422.html

分享到:

/*如:
输入: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 19: printf("%s","百");  break;
            case 20: printf("%s","千");  break;
            case 21: printf("%s","万");  break;
            case 22: printf("%s","十");  break;
            case 23: printf("%s","百"); break;
            case 24: printf("%s","千"); break;
            default:  printf("%s","");  break;
         }
      }     
    }
    printf("%s","圆");
}   

void Print_X(char a[])
{
   int i;
   for(i=0; i<4; i++)
   {
      switch(a[i])/*读入数字*/
      {
         case '0': printf("%s",p[0]); break;
         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("%s",p[0]); ; break;
      }
      switch(i)/*读入单位*/
      {
         case 0: printf("%s","角"); break;
         case 1: printf("%s","分"); break;
         case 2: printf("%s","厘"); break;
         case 3: printf("%s","毫"); break;
         default: printf("It's error"); break;
      }   
   }   
}       

阅读(3075) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册