Solution for Exercise 5-2
ex0502
#include <stdio.h> int main() { printf("%d\n",127); printf("%f\n",3.1415926535); printf("%d\n",122013); printf("%f\n",0.00008); return(0); }
Output
127
3.141593
122013
0.000080
Notes
* The \n
(newline) at the end of the printf() formatting string isn't required, but it does help keep the output clean.
* To see how the compiler deals with misplaced conversion characters, change one of the %d
placeholders to %f
or vice-versa. Rebuild the code to see what sort of errors develop.
* Here's a bonus that earns you some For Dummies points: Re-write the code so that a single printf() statement displays all the values, each on a line by itself. (I won't show you the code for that solution; you'll know when you got it right by looking at the output.)
Copyright © 1997-2024 by QPBC.
All rights reserved