Math Functions: The Mean or Average Value of a Series



Extended __fastcall Mean(const double * Data, const int Data_Size);

The Mean() function considers an array of numbers and calculates the average value of those numbers. The function takes two arguments. The first, Data, is the name of the array of numbers. These number could integers or floating numbers. The second argument, Data_Size represents the number-1 of members of the array. You can type an integral number as the Data_Size or you can use the sizeof operator to get the dimension of the array and subtract 1 from it. After the calculation, the function returns a long double-precision number as the average of the numbers.

Here is an example:

void __fastcall TForm1::Button1Click(TObject *Sender)
	double Values[] = { 12.55, 10.15, 980.22, 50.50, 280.12 };
	int Size = (sizeof(Values) / sizeof(double)) - 1;

	double Average = Mean(Values, Size);

	Edit1->Text = Average;



Home Copyright © 2010-2016, FunctionX