Solution for Exercise 12-6

ex1206

#include <stdio.h>

int main()
{
    float marketclose[] = { 14450.06, 14458.62, 14539.14, 14514.11, 14452.06 };
    int day;

    puts("Stock Market Close");
    for(day=0;day<5;day++)
        printf("Day %d: %.2f\n",day+1,marketclose[day]);
    return(0);
}

Notes

* Another popular way to initialize an array is to place its elements on lines by themselves. For example:

* The final curly bracket can go on a line by itself if you like, just remember not to place a comma after the final value in the array or the compiler thinks you goofed up and missed a value:

* It's also common to organize array elements into rows and columns when they're initialized:

* In Line 10 (the printf() statement), you again see the day+1 construction, which displays output using the human method of starting at 1 instead of zero.