/**********************************
  File:  hw2p4-alt.c

for integer n>=1,  print table with
integer i, ranging from 1 to n, in the 
left column and the average of the 
first i numbers in the  right column

***********************************/

#include <stdio.h>
#include "simpio.h"

/* 
   compare this program to hw2p4.c  Here we 
   are using an embedded assignment in the while
   loop.  Note how compact this makes the code.
*/

void main()
{
  int n=0, i=0;
  double sum=0.0;

  printf("Enter an integer n: ");
  while ((n = GetInteger()) < 1)
    printf("n must be positive, try again: ");

  printf("i\t\tavg\n-----------------------------\n");
  for (i=1; i<=n; i++)
    printf("%d\t\t%.2f\n", i, (sum += i)/i);
}

