fbpx

C++: Calculate Geometric Mean

Bjarne-stroustrup
 

void Geometric_Mean_Array(double & mean_normal, const double * a, const int n)
//Function that calculates the geometric mean (geometric average) of an array of numbers
{ 	
	double x = a[0];
	for(int i = 1; i < n; i++) 
	{	
		x = x * a[i]; 
	}
	mean_normal = pow(x,(double)1/n); 
}