0% found this document useful (0 votes)
4 views

Calculation of The Harmonic of An Input Data Using DO Loop

This document contains a program to calculate the harmonic mean of an input data set using a DO loop. The program prompts the user to enter the number of data points, then uses a loop to read each input value and calculate the sum of the reciprocals. It then displays the harmonic mean and number of data points as output.

Uploaded by

mengelhu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Calculation of The Harmonic of An Input Data Using DO Loop

This document contains a program to calculate the harmonic mean of an input data set using a DO loop. The program prompts the user to enter the number of data points, then uses a loop to read each input value and calculate the sum of the reciprocals. It then displays the harmonic mean and number of data points as output.

Uploaded by

mengelhu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

EXP NO:

DATE :

Calculation of the harmonic of an input data Using DO loop


AIM:
A program to calculate the harmonic of an input data set is shown below.

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:

Enter number of points:


6
4
Enter next number:
10.
Enter next number:
5.
Enter next number:
2.
Enter next number:
5.
The harmonic mean of this data set is: 4.000000
The number of data points is: 4

RESULT:

You might also like