How to resolve the algorithm Averages/Arithmetic mean step by step in the Oberon-2 programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Averages/Arithmetic mean step by step in the Oberon-2 programming language

Table of Contents

Problem Statement

Write a program to find the mean (arithmetic average) of a numeric vector. In case of a zero-length input, since the mean of an empty set of numbers is ill-defined, the program may choose to behave in any way it deems appropriate, though if the programming language has an established convention for conveying math errors or undefined values, it's preferable to follow it.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Averages/Arithmetic mean step by step in the Oberon-2 programming language

Source code in the oberon-2 programming language

MODULE AvgMean;
IMPORT Out;
CONST MAXSIZE = 10;
PROCEDURE Avg(a: ARRAY OF REAL; items: INTEGER): REAL;
VAR
	i: INTEGER;
	total: REAL;
BEGIN
	total := 0.0;
	FOR i := 0 TO LEN(a) -  1 DO
		total := total + a[i]
	END;
	RETURN total/LEN(a)
END Avg;
VAR
	ary: ARRAY MAXSIZE OF REAL;
BEGIN
	ary[0] := 10.0;
	ary[1] := 11.01;
	ary[2] := 12.02;
	ary[3] := 13.03;
	ary[4] := 14.04;
	ary[5] := 15.05;
	ary[6] := 16.06;
	ary[7] := 17.07;
	ary[8] := 18.08;
	ary[9] := 19.09;
	Out.Fixed(Avg(ary),4,2);Out.Ln
END AvgMean.

  

You may also check:How to resolve the algorithm Array length step by step in the Ring programming language
You may also check:How to resolve the algorithm Continued fraction step by step in the C++ programming language
You may also check:How to resolve the algorithm Evaluate binomial coefficients step by step in the Burlesque programming language
You may also check:How to resolve the algorithm Square but not cube step by step in the ALGOL-M programming language
You may also check:How to resolve the algorithm The sieve of Sundaram step by step in the Nim programming language