/*
   Functions taking an array. See Nyhoff P457-460

   Note arrays are transferred by-reference and not by-value,
   so if you change the array in the function, you also
   change the array used to call the functions.
*/

#include <iostream>
using namespace std;

double dotproduct(double a[],double b[],int size)
{
   double dot=0;
   for (int i=0;i<size;i++)
        dot+=a[i]*b[i];

   return dot;
}

int main()
{
   const int DIM=3;

   double x[DIM] = {1.0 , 2.0,  3.0};
   double y[DIM] = {10.0, 2.0, 30.0 };

   cout << "x=" << x[0] << " "
                << x[1] << " "
                << x[2] << " "
                << endl;

   cout << "y=" << y[0] << " "
                << y[1] << " "
                << y[2] << " "
                << endl;

   cout << "Dot product = " << dotproduct(x,y,DIM) << endl;

   return 0;
}

