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);
}

Notes

* You don't have to remember the \n (newline) in the printf() formatting string, 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.)