The array samples contains 7 8-bit unsigned binary numbers (integers) as shown b
ID: 3564494 • Letter: T
Question
The array samples contains 7 8-bit unsigned binary numbers (integers) as shown below. Write a program which computes the mean and variance of the numbers in samples and stores them in the variables mean and variance, respectively. In the computation, you may ignore any fraction, but minimize the numerical error. You must use loops. Your program should work for any numbers stored in samples.
RAMStart=$0800 and
ROMStart=$4000.
samples DC.B $10,$25,$90,$CC,$56,$3F,$E1
mean DS.B 1
variance DS.W 1
Explanation / Answer
PROGRAM MeanVariance IMPLICIT NONE INTEGER, PARAMETER :: MAX_SIZE = 50 ! maximum array size REAL, DIMENSION(1:MAX_SIZE) :: Data ! input array REAL :: Mean, Variance, StdDev ! results INTEGER :: n ! actual array size INTEGER :: i ! running index READ(*,*) n ! read in input array READ(*,*) (Data(i), i = 1, n) WRITE(*,*) "Input Data:" ! display the input WRITE(*,*) (Data(i), i = 1, n) Mean = 0.0 ! compute mean DO i = 1, n Mean = Mean + Data(i) END DO Mean = Mean / n Variance = 0.0 ! compute variance DO i = 1, n Variance = Variance + (Data(i) - Mean)**2 END DO Variance = Variance / (n - 1) StdDev = SQRT(Variance) ! compute standard deviation WRITE(*,*) ! display result WRITE(*,*) "Mean : ", Mean WRITE(*,*) "Variance : ", Variance WRITE(*,*) "Standard Deviation : ", StdDev WRITE(*,*) WRITE(*,*) "Analysis Table:" ! display an analysis table DO i = 1, n IF (Data(i) > Mean + StdDev) THEN WRITE(*,*) Data(i), Data(i) - Mean, "Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.