(adsbygoogle = window.adsbygoogle || []).push({}); Trying to write a single Fortran program that calculates the arithmetic mean, rms (root-mean-square) average, geometric mean, and harmonic mean for a set of numbers (for example - 4 4 4 4 4).

I don't know if I am doing the write way. Please guide me.

PROGRAM ComputingMeans

IMPLICIT NONE

INTEGER :: Count

INTEGER :: Valid

INTEGER :: i

REAL :: Item

REAL :: Arithmetic, Geometric, Harmonic ! Arithmetic, geometric and harmonic mean

WRITE(*,*) "Write count of items:"

READ(*,*) Count

! Reads items and computes arithmetic, geometric and harmonic mean

Valid = 0

Arithmetic = 0.

Geometric = 1.

Harmonic = 0.

DO i = 1, Count

WRITE(*,*) "Write items:"

READ(*,*) Item

IF (Item > 0) THEN

Valid = Valid + 1

Arithmetic = Arithmetic + Item

Geometric = Geometric * Item

Harmonic = Harmonic + (1 / Item)

END IF

END DO

! Writes results on screen

IF (Valid > 0) THEN

WRITE(*,"(A,I3,A)") "Count of valid items: ", Valid, "."

Arithmetic = Arithmetic / Valid

Geometric = Geometric**(1./Valid)

Harmonic = Valid / Harmonic

WRITE(*,"(A,F9.6,A)") "Arithmetic mean: ", Arithmetic, "."

WRITE(*,"(A,F9.6,A)") "Geometric mean: ", Geometric, "."

WRITE(*,"(A,F9.6,A)") "Harmonic mean: ", Harmonic, "."

ELSE

WRITE(*,*) "ERROR: None of the input is positive!"

END IF

END PROGRAM ComputingMeans

**Physics Forums | Science Articles, Homework Help, Discussion**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Need Help with my Fortran Code

**Physics Forums | Science Articles, Homework Help, Discussion**