#include <iostream.h>
#include <conio.h>
#include <vcl.h>
#pragma hdrstop
// prototyp funkcji HarmonicMean()
long double HarmonicMean(const double *Data,
                         const int Data_Size);
int main()
{
  double d[] = {1, -2, 3.9, 4.9, 5, 9, -7, 0 };
  long double HM = HarmonicMean(d, ARRAYSIZE(d) - 1);
  cout << "Srednia harmoniczna= " << HM << endl;

  getch();
  return 0;
}
//---------------------------------------------------------
long double HarmonicMean(const double *Data,
                         const int Data_Size)
{
  long double sum = 0, HM;
  for (int i=0; i<= Data_Size; i++)
    {
      try {
        if ((! Data[i]) || (Data[i]<0)) throw Data[i];
        sum += 1.0/Data[i];
      }
      catch(const double *Data){
        cout << "Niedozwolone parametry funkcji HM()" << endl;
      }

    };
    HM = (Data_Size+1.0)/sum;
  return HM;
}

