Example of C language-based bank Printing Program

Source: Internet
Author: User

Introduction
The analog bank's capital amount output is as follows:
345
Sanyunwu

Method/step
First open VC ++

File> New

Create a blank C ++ document

First declare the header file

Copy codeThe Code is as follows: # include <stdio. h>


Declare VariablesCopy codeThe Code is as follows: char * p [10] = {"0", "1", "2", "3", "4", "5", "6 ", "7", "8", "9 "};


Since user-defined functions are used, declareCopy codeCode: void PrintInterger (char a [], int len);/* output integer part */
Void PrintDecimal (char a [], int len);/* output fractional part */


Function 1 is used to output the integer part. It mainly uses switch case for matching and conversion.Copy codeThe Code is as follows: void PrintInterger (char a [], int len)

{

Int I, j, tag1, tag2, tag3;

Tag1 = (a [len-6] = '0' & a [len-7] = '0' & a [len-8] = '0 ');

Tag2 = (a [len-14] = '0' & a [len-15] = '0' & a [len-16] = '0 ');

Tag3 = (a [len-22] = '0' & a [len-23] = '0' & a [len-24] = '0 ');

Printf ("Your money is \ n ");

For (I = 0, j = len; I <len & j> 0; I ++, j --)

{

If (a [I] = '0' & I! = Len-1)

{

If (j = 5 & tag1) | (j = 13 & tag2) | (j = 21 & tag3 ))

;

Else if (j = 21 &&! Tag3) | (j = 5 &&! Tag1) | (j = 13 &&! Tag2 ))

Printf ("Ten Thousand ");

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 ("0 ");

Else

;

}

Else if (a [I] = '0' & I = len-1)

;

Else if (a [I]! = '0 ')

{

/* Conversion from Arabic numerals to Chinese characters */

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;

}

/* Output the corresponding unit */

Switch (j)

{

Case 2:

Case 6:

Case 10:

Case 14:

Case 18:

Case 22: printf ("% s", "10"); break;

Case 3:

Case 7:

Case 11:

Case 15:

Case 19:

Case 23: printf ("% s", "Hundred"); break;

Case 4:

Case 8:

Case 12:

Case 16:

Case 20:

Case 24: printf ("% s", "thousands"); break;

Case 5:

Case 13:

Case 21: printf ("% s", "Ten Thousand"); break;

Case 9:

Case 17: printf ("% s", ""); break;

Default: printf ("% s", ""); break;

}

}

}

Printf ("% s", "circle ");

}

Function 2 is used to output the decimal part. It mainly uses switch case for matching conversion.Copy codeCode: void PrintDecimal (char a [], int len)

{

Int I;

For (I = 0; I <len; I ++)

{

/* Conversion from Arabic numerals to Chinese characters */

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;

}

/* Output unit */

Switch (I)

{

Case 0: printf ("% s", ""); break;

Case 1: printf ("% s", "points"); break;

Case 2: printf ("% s", ""); break;

Case 3: printf ("% s", ""); break;

Default:; break;

}

}

}

Main function, the role of variables I explainedCopy codeThe Code is as follows: int main (void)

{

Char Number [128];/* used to store user input numbers */

Char Interger [64], Decimal [64];/* store the integer and Decimal parts of the input number respectively */

Int lenI, lenD;/* respectively record the length of the integer and decimal part */

Int I, j;

Puts ("************************************* ");

Puts ("* This is a print program *");

Puts ("* used in a bank *");

Puts ("************************************* ");

Puts ("please input the money :");

Gets (Number );

I = 0; j = 0;

/* Process the integer part of the input number */

While (Number [I]! = '/0') & (Number [I]! = '.') & (Number [I]> = '0') & (Number [I] <= '9 '))

{

Interger [I] = Number [I];

I ++;

}

LenI = I;

If (Number [I] = '.')

{

I ++;

/* Process the fractional part of the input number */

While (Number [I]! = '/0' & Number [I]> = '0' & Number [I] <= '9 ')

{

Decimal [j ++] = Number [I ++];

}

/* Four digits after the decimal point */

If (j> = 4) & (Decimal [4]> '5 '))

{

Decimal [3] + = 1;/* perform the 4-in-5 operation */

Decimal [4] = '/0 ';

}

}

If (j> = 4)

LenD = 4;

Else

LenD = j;

PrintInterger (Interger, lenI );

PrintDecimal (Decimal, lenD );

Printf ("\ n ");

Return 0;

}

Running result

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.