making the printf look better in g05 !!
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 PresentationTRANSCRIPT
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 */
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);