Home

Math Functions: The Sum Of Squares of a Series

     

Introduction

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

The SumOfSquares() function performs a double operation on an array. First it calculates the square S of each member of the array; then it calculates the total of the individual S values. The first argument of the function, Data, is the name of the array, the second argument, Data_Size represents the dimension of the array minus 1.

To calculate the total of the squares, declare an array variable. You can initialize the array by providing the necessary list of numbers. Otherwise, request the different numbers from the user. The function will take care of the rest.

Here is example:

//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
	Double Grades[] = { 12.50, 14.00, 16.00, 15.50,
			    12.00, 10.50, 14.50, 17.50 };
	int Size = (sizeof(Grades)/sizeof(double)) - 1;

	Double Total = SumOfSquares(Grades, Size);
	Edit1->Text = FloatToStr(Total);
}
//---------------------------------------------------------------------------
   

 

   
     
 

Home Copyright © 2010-2016, FunctionX