Upload
mengelhu
View
212
Download
0
Embed Size (px)
DESCRIPTION
Programs
Citation preview
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 meanINTEGER :: i ! Loop indexINTEGER :: n ! Number of input samplesREAL :: sum_rx = 0. ! Sum of reciprocals of input valuesREAL :: 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 / xEND DO! Calculate the harmonic meanh_mean = REAL (n) / sum_rx! Tell user.WRITE (*,*) 'The harmonic mean of this data set is:', h_meanWRITE (*,*) 'The number of data points is: ', nEND PROGRAM
OUTPUT:
Enter number of points:64Enter next number:10.Enter next number:5.Enter next number:2.Enter next number:5.The harmonic mean of this data set is: 4.000000The number of data points is: 4
RESULT: