The scalar product of two vectors u=(u0,…,un−1) and v=(v0,…,vn−1) is ∑i=0n−1 ui vi.
Write a function that returns the scalar product of u and v.
Interface
C++ | double scalar_product(const vector<double>& u, const vector<double>& v); |
C | double scalar_product(int n, double u[n], double v[n]); |
Java | public static double scalarProduct(double[] u, double[] v); |
Python | scalar_product(u, v) # returns float |
MyPy | scalar_product(u: list[float], v: list[float]) -> float |
Precondition
The vectors u and v have the same size.
Observation You only need to submit the required procedure; your main program will be ignored.