{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

W06-Ident-Var-Op

# W06-Ident-Var-Op - Identifiers Variables Operators 1 printf...

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

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

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

View Full Document
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 10/3/05 6 Input Example # include <stdio.h> int main( void ) { int a; float x; double z; scanf(" %d %f %lf ", &a, &x, &z); printf(" %d\n%f\n%f\n ", a, x, z); return 0; } Note!
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}