program means c c -- find the mean and standard deviation c -- figure 2.3 c integer out, length, max real x(80), mean, std common /inout/ out c out = 6 max = 80 write(out, 101) 10 call input(x, length, max) if (length .lt. 2) goto 99 call meanst(x, length, mean, std) call output(x, length, mean, std) goto 10 99 stop 101 format(' calculation of mean', * ' and standard deviation') end subroutine input(x, n, max) c -- get values for n and array x c integer out, i, n, max real x(1) common /inout/ out c 10 write(out, 101) read(*, 102) n if (n .gt. max) goto 10 if (n .lt. 2) return do 20 i = 1, n write(out, 103) i read(*, 104) x(i) 20 continue return 101 format(' how many points? ' ) 102 format(i2) 103 format('+', i3, ':' ) 104 format(f10.0) end subroutine output(x, n, mean, std) c c -- print the answers c integer out, n real x(1), mean, std common /inout/ out c write(out, 101) n, mean, std return 101 format(' for', i3, ' points, mean =', f8.4, * ', sigma =', f8.4) end subroutine meanst(x, length, mean, std) c c -- find the mean and standard deviation c integer length, i real x(1), mean, std, sum, sumsq, xi c sum = 0.0 sumsq = 0.0 do 10 i = 1, length xi = x(i) sum = sum + xi sumsq = sumsq + xi*xi 10 continue mean = sum / length std = sqrt((sumsq - sum*sum/length)/(length -1)) return end