How to resolve the algorithm Averages/Arithmetic mean step by step in the Forth programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Averages/Arithmetic mean step by step in the Forth 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 Forth programming language
Source code in the forth programming language
: fmean ( addr n -- f )
0e
dup 0= if 2drop exit then
tuck floats bounds do
i f@ f+
1 floats +loop
0 d>f f/ ;
create test 3e f, 1e f, 4e f, 1e f, 5e f, 9e f,
test 6 fmean f. \ 3.83333333333333
You may also check:How to resolve the algorithm Loops/Break step by step in the REBOL programming language
You may also check:How to resolve the algorithm Plot coordinate pairs step by step in the ALGOL 68 programming language
You may also check:How to resolve the algorithm Extreme floating point values step by step in the XPL0 programming language
You may also check:How to resolve the algorithm Quoting constructs step by step in the Ecstasy programming language
You may also check:How to resolve the algorithm Sorting algorithms/Insertion sort step by step in the REALbasic programming language