A vector is a ID array (like the ones we\'ve been studying in class) with variou
ID: 3581747 • Letter: A
Question
A vector is a ID array (like the ones we've been studying in class) with various mathematical proper ties. Consider a vector, V, of length n: V = (v_1, v_2, v_3, v_n) The dot product of U and V, denoted U middot V, is the sum of the pairwise products of their elements: U middot V = (u_1 middot v_2 + u_2 middot v_2 + u_3 middot v_3 + + u_n v v_n) Write a function (NOT A PROGRAM) that calculates and returns the dot product of two vectors of the same length; the dot product returned should be a float scalar. It should lake the following arguments: two float arrays of the same length; an int representing the length of both arrays.Explanation / Answer
float dot_product(float u[],float v[],int n)
{
float product=0;
for(int i=0;i<n;i++)
{
product+=u[i]*v[i];
}
return product;
}
Explanation:
As reuiqred it takes two arrays and size as parameter and calculates dot product
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.