*****Listing 2***** declare array to hold last N smaples. load array with first N samples set array_ptr to 1 calculate initial TOTAL for array calculate initial result ( TOTAL / N ) while sampling not finished take sample calculate TOTAL = TOTAL + sample - array(array_ptr) array(array_ptr) = sample result = TOTAL / n store result if array_ptr < n array_ptr = array_ptr + 1 else array_ptr = 1 end if end while