How to resolve the algorithm Averages/Arithmetic mean step by step in the Sidef programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Averages/Arithmetic mean step by step in the Sidef 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 Sidef programming language

Source code in the sidef programming language

func avg(Array list) {
    list.len > 0 || return 0;
    list.sum / list.len;
}

say avg([Math.inf, Math.inf]);
say avg([3,1,4,1,5,9]);
say avg([1e+20, 3, 1, 4, 1, 5, 9, -1e+20]);
say avg([10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0.11]);
say avg([10, 20, 30, 40, 50, -100, 4.7, -1100]);

  

You may also check:How to resolve the algorithm Sort a list of object identifiers step by step in the Raku programming language
You may also check:How to resolve the algorithm Compare a list of strings step by step in the ALGOL 68 programming language
You may also check:How to resolve the algorithm Hello world/Graphical step by step in the Icon and Unicon programming language
You may also check:How to resolve the algorithm Haversine formula step by step in the Factor programming language
You may also check:How to resolve the algorithm Averages/Mean angle step by step in the R programming language