/*
 * Read positive numbers from stdin, store them in an array.  Print out the
 * array when done.  (This version has some more kinds of debugging print
 * statemetns, in help understand what's going on in the input loop.)
 */
#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.
      */
    while (x > 0) {

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

        /*
         * Increment array index.
	 */
	printf("i, pre incr =%d\n", i);		/* DEBUGGING */
	i = i + 1;
	printf("i, post incr =%d\n", i);	/* DEBUGGING */

	/*
	 * Read in next number.
	 */

	scanf("%lf", &x);
	a[i] = x;
	printf("i, end-of-loop =%d\n", i);	/* DEBUGGING */
	printf("a[%d] = %f\n", i, a[i]);	/* DEBUGGING */

    }

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

    return 0;
}