Calculation of The Harmonic of An Input Data Using DO Loop
Calculation of The Harmonic of An Input Data Using DO Loop
DATE :
PROGRAM:
PROGRAM harmon
! Purpose:
! To calculate harmonic mean of an input data set, where each
! input value can be positive, negative, or zero.
IMPLICIT NONE
! List of variables:
REAL :: h_mean ! Harmonic mean
INTEGER :: i ! Loop index
INTEGER :: n ! Number of input samples
REAL :: sum_rx = 0. ! Sum of reciprocals of input values
REAL :: x = 0. ! Input value
! Get the number of points to input.
WRITE (*,*) 'Enter number of points: '
READ (*,*) n
! Loop to read input values.
DO i = 1, n
! Get next number.
WRITE (*,*) 'Enter next number: '
READ (*,*) x
! Accumulate sums.
sum_rx = sum_rx + 1.0 / x
END DO
! Calculate the harmonic mean
h_mean = REAL (n) / sum_rx
! Tell user.
WRITE (*,*) 'The harmonic mean of this data set is:', h_mean
WRITE (*,*) 'The number of data points is: ', n
END PROGRAM
EXP NO:
DATE :
OUTPUT:
RESULT: