W06-Ident-Var-Op - Identifiers, Variables, Operators...

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

View Full Document Right Arrow Icon
10/3/05 1 Identifiers, Variables, Operators 10/3/05 2 printf formatting • %f can be used to print either float or double variables. • Real number output formatting, %n.mf m specifies number of digits to right of decimal n specifies minimum width of printing field if n is negative, then left justified in field 10/3/05 3 Formatting Example • If x = 3.1415926 then printf(" %10.3f ",x) will print: 3.142 But printf(" %0.3f ", x) prints 3.142 m=3 printing spaces n=10 printing spaces
Background image of page 1

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

View Full DocumentRight Arrow Icon
10/3/05 4 Printing Integers and Strings • Integers and strings can also use field width • %nd, %ns where n is again min field width. Example: printf(" %-10d%10s ", 21," abcde ") 21 abcde 10 wide 10 wide 8 wide 5 wide 10/3/05 5 Inputting Value from KB • The function scanf() waits for input from keyboard. • Input can be integer (%d), float (%f), double( %lf ), or string (%s). scanf(string, &var1, &var2, …); string contains conversion specifiers for var1, var2, etc. address-of operator
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 7

W06-Ident-Var-Op - Identifiers, Variables, Operators...

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

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