Average

From SCAR Divi Manual
Revision as of 08:16, 28 June 2011 by Freddy (talk | contribs) (Created page with "==Definition== <source lang="scar" lines="false"> function Average(Values: TExtendedArray): Extended; </source> <source lang="scar"> function Average(Values: TExtendedArray): Ex...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Definition

function Average(Values: TExtendedArray): Extended;
function Average(Values: TExtendedArray): Extended;
var
  i, l: Integer;
begin
  Result := 0;
  l := Length(Values);
  if l = 0 then Exit;
  for i := 0 to l - 1 do
    Result := Result + Values[i];
  Result := Result / l;
end;

Availability

SCAR Divi 3.00 > Current

Description

Calculates the arithmetic mean of a given set of extended floating point values specified by the TExtendedArray Values.

Example

var
  Values: array of Extended;
begin
  Values := [1.2, 1.9, 2.9, 5.55, 8.69];
  WriteLn(Average(Values));
end.

Output:

4,048