Solution for Exercise 6-4

ex0604

#include <stdio.h>

int main()
{
    char c;
    int i;
    float f;
    double d;

    c = 'a';
    i = 1;
    f = 19.8;
    d = 20000.009;

    printf("%c\n%d\n%f\n%f\n",c,i,f,d);
    return(0);
}

Output

a
1
19.799999
20000.009000

Notes

* This exercise is designed to remind you to display floating-point values using formatted output, such as %.2f as opposed to just %f. When you don't format the output (as shown by the printf() statement at Line 15), the displayed results are as accurate as the computer can make them, but would perhaps confuse the program's user.