How to resolve the algorithm Averages/Arithmetic mean step by step in the Elena programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Averages/Arithmetic mean step by step in the Elena 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 Elena programming language
Source code in the elena programming language
import extensions;
extension op
{
average()
{
real sum := 0;
int count := 0;
var enumerator := self.enumerator();
while (enumerator.next())
{
sum += *enumerator;
count += 1;
};
^ sum / count
}
}
public program()
{
var array := new int[]{1, 2, 3, 4, 5, 6, 7, 8};
console.printLine(
"Arithmetic mean of {",array.asEnumerable(),"} is ",
array.average()).readChar()
}
You may also check:How to resolve the algorithm ISBN13 check digit step by step in the D programming language
You may also check:How to resolve the algorithm Factors of an integer step by step in the Objeck programming language
You may also check:How to resolve the algorithm Abelian sandpile model/Identity step by step in the Python programming language
You may also check:How to resolve the algorithm Count occurrences of a substring step by step in the Racket programming language
You may also check:How to resolve the algorithm Priority queue step by step in the CoffeeScript programming language