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

Published on 12 May 2024 09:40 PM

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

Source code in the newlisp programming language

(define (Mean Lst)
   (if (empty? Lst)
      0
      (/ (apply + Lst) (length Lst)))) 
 
 (Mean (sequence 1 1000))-> 500
 (Mean '()) -> 0


  

You may also check:How to resolve the algorithm Unicode strings step by step in the Ada programming language
You may also check:How to resolve the algorithm Thiele's interpolation formula step by step in the Rust programming language
You may also check:How to resolve the algorithm Catalan numbers step by step in the V (Vlang) programming language
You may also check:How to resolve the algorithm Mandelbrot set step by step in the ALGOL W programming language
You may also check:How to resolve the algorithm Align columns step by step in the C programming language