/*
 * Read positive numbers from stdin, store them in an array.  Print out the
 * array when done.  !With bounds checking!
 */
#include <stdio.h>

int main() {

    int i = 0;                  /* Array index for input. */
    int j = 0;                  /* Array index for output. */
    double x;                   /* Input value */
    double a[5];                /* Array to hold numbers */

    /*
     * Prompt and read first number.
     */
    printf("Input positive numbers, negative to stop: ");
    scanf("%lf", &x);

     /*
      * Loop until negative number input, or we run out of room in the array,
      * which ever occurs first.
      */
    while (x > 0 && i < 5) {

        /*
         * Store input in next array element.
         */
        a[i] = x;

        /*
         * Increment array index.
         */
        i = i + 1;

        /*
         * Read in next number.
         */
        scanf("%lf", &x);

    }

    /*
     * Print out the array.
     */
    while (j < i) {
        printf("a[%d] = %f\n", j, a[j]);
        j++;
    }

    return 0;
}