Lecture10_handout - Standard output function: printf()...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
1 EE140: Introduction to 0t o d u c t o t o Programming Concepts for Engineers Lecture 10 1 Standard input/output functions Standard output function: printf() printf("formatted string", var 1 , var 2 , …, var n ); Formatted string: xt will be printed out as it is text will be printed out as it is % is the format indicator, which tells the computer that the value of a variable/expression will be printed out. The number of format indicators should match with the number of arguments at the end The format indicator should match with the data type of the argument Format indicators recognized by printf() d or %i har, short, int %d or %i char, short, int %e, %f, %g float, double %c text character (char) %s text string (char array) 2 Example 1: Displaying real values Real value Output using f Output sing %e Output sing %g %f using %e using %g 0.0 0.000000 0.000000e+00 0 23000.0 23000.000000 2.300000e+04 23000 2300000.0 2300000.000000 2.300000e+06 2.3e+06 0.0001234567 0.000123 1.234567e-04 0.000123 1e-23 0.000000 1.000000e-23 1e-23 3 -- Default for %f and %e: 6 digits after the decimal point -- %g: the minimum display of %f and %e with only significant digits -- We will discuss some advanced format controls such as “ %m.n f later on Advanced format control using printf() %[flag][width].[precision] format indicator flag: - left aligned +s i gn is always displayed, even for a positive number <space> insert a space before a positive number 0 pad a field with leading zeros
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/04/2011 for the course EE 150 taught by Professor Lanxiang during the Spring '11 term at Montgomery College.

Page1 / 3

Lecture10_handout - Standard output function: printf()...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online