making the printf look better in g05 !!

2
Making the PRINTF Look Better in G05 !! EXAMPLE: printf ("%f%d", a, b) ; /* Produces lots of decimal places for variable ‘a’….. 142.101567 … defaults to 6 */ But you can control the output as follows: printf ("%x.yf%zd", a, b) ; /* The x & z specify the total number of default places (always supplied, more provided if needed) including the decimal point and any sign . The y specifies the exact number of place to the right of the decimal point. This control allows the programmer to better align output data. The x, y & z are optional. printf ("%.2f%d", a, b) ; /* Now produces only 2 places to the right of the decimal for variable ‘a’….. 142.10 */

Upload: karleigh-williams

Post on 31-Dec-2015

13 views

Category:

Documents


1 download

DESCRIPTION

Making the PRINTF Look Better in G05 !!. EXAMPLE: printf ("%f%d", a, b) ; /* Produces lots of decimal places for variable ‘a’….. 142.101567 … defaults to 6 */ But you can control the output as follows: - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Making the PRINTF Look Better in G05 !!

Making the PRINTF Look Better in G05 !!

EXAMPLE:printf ("%f%d", a, b) ; /* Produces lots of decimal places for variable ‘a’….. 142.101567 … defaults to 6 */

But you can control the output as follows:

printf ("%x.yf%zd", a, b) ; /* The x & z specify the total

number of default places (always supplied, more provided if needed)

including the decimal point and any sign . The y specifies the exact number of place to the right of the decimal point. This control allows the programmer to better align output data. The x, y & z are optional.

printf ("%.2f%d", a, b) ; /* Now produces only 2 places to the right of the decimal for variable ‘a’….. 142.10 */

Page 2: Making the PRINTF Look Better in G05 !!

Example

• Say you want to print– The pole is 42.735 feet high– The pole is 4.123 feet high– The pole is 192.678 feet high

• You would use– printf (“The pole is %.3f feet high\n”,hgt);