C Language Writing Bank printing program Instance reference _c language

Source: Internet
Author: User
Tags switch case

Brief Introduction
Analog Bank of capital output for example
345
Three restaurants

Method/Step
First Open VC + +

File "" New

Create a C + + blank Document

Declare header file first

Copy Code code as follows:

#include <stdio.h>


declaring variables
Copy Code code as follows:

Char *p[10]={"0", "one", "two", "three", "four", "five", "six", "seven", "eight", "Nine"};


Because of the use of a custom function, we first declare
Copy Code code as follows:

void Printinterger (char a[], int len);/* Output Integer PART * *
void Printdecimal (char a[],int len)/* Output Decimal Part * *


Function 1, for outputting integer parts, mainly using switch case for matching conversions
Copy Code code 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 = && Tag2) | | (j = = && Tag3))

;

else if (j = &&! Tag3) | | (j = = 5 &&! Tag1) | | (j = && Tag2))

printf ("Million");

else if (j = = 9 | | j = = 17)

printf ("billion");

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 ')

{

/* The conversion of 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 corresponding unit * *

Switch (j)

{

Case 2:

Case 6:

Case 10:

Case 14:

Case 18:

Case 22:printf ("%s", "ten"); 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", "thousand"); Break

Case 5:

Case 13:

Case 21:printf ("%s", "million"); Break

Case 9:

Case 17:printf ("%s", "billion"); Break

default:printf ("%s", ""); Break

}

}

}

printf ("%s", "Round");

}


Function 2, for outputting decimal parts, mainly using switch case for matching conversion
Copy Code code as follows:

void Printdecimal (char a[],int len)

{

int i;

for (i=0; i<len; i++)

{

/* The conversion of 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 corresponding unit * *

Switch (i)

{

Case 0:printf ("%s", "angle"); Break

Case 1:printf ("%s", "Min"); Break

Case 2:printf ("%s", "pct"); Break

Case 3:printf ("%s", "Hao"); Break

Default:; Break

}

}

}


The main function, the function of the variable I explained
Copy Code code as follows:

int main (void)

{

Char number[128];/* is used to hold the number entered by the user.

Char interger[64], decimal[64];/* an integer and a decimal part that holds the input number respectively.

int leni,lend;/* records the length of integers and decimal parts separately.

int i,j;

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

Puts ("* This are 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 number entered.

while ((number[i]!= '/0 ') && (number[i]!= '. ') && (number[i] >= ' 0 ') && (Number[i] <= ' 9 '))

{

Interger[i]=number[i];

i++;

}

LenI = i;

if (number[i]== '. ')

{

i++;

/* Processing the number of inputs of the decimal part of the * * *

while (number[i]!= '/0 ' && number[i] >= ' 0 ' && number[i] <= ' 9 ')

{

Decimal[j++]=number[i++];

}

/* Accurate to 4 digits after the decimal point * *

if ((J >= 4) && (Decimal[4] > ' 5 '))

{

decimal[3]+=1;/* carry out 4 homes five into operation * *

DECIMAL[4] = '/0 ';

}

}

if (J >= 4)

LenD = 4;

Else

LenD = j;

Printinterger (Interger, LenI);

Printdecimal (Decimal,lend);

printf ("\ n");

return 0;

}



Run results

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.