Scalar product P71310


Statement
 

pdf   zip   main.cc   main.c   main.java   main.py

The scalar product of two vectors u=(u0,,un1)u=(u_0,\dots,u_{n-1}) and v=(v0,,vn1)v=(v_0,\dots,v_{n-1}) is i=0n1uivi\sum_{i=0}^{n-1} u_i v_i.

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.

Information
Author
Jordi Petit
Language
English
Translator
Carlos Molina
Original language
Catalan
Other languages
Catalan
Official solutions
C C++ Java Python
User solutions
C C++ Java Python