Answer to Question #200386 in C++ for খোকা বাবু

Question #200386

Write the program of vector 

and dot product using user defined function in c++


1
Expert's answer
2021-05-30T07:12:52-0400
#include <bits/stdc++.h>
#define n 3
using namespace std;
int dotProduct(int vect_A[], int vect_B[])
{


    int product = 0;


    // Loop for calculate cot product
    for (int i = 0; i < n; i++)


        product = product + vect_A[i] * vect_B[i];
    return product;
}
int main()
{


    int vect_A[3],vect_B[3];
    cout<<"Enter values for first vector : ";
    for(int i=0;i<3;i++)
    {
        cin>>vect_A[i];
    }
    cout<<"Enter values for second vector : ";
    for(int i=0;i<3;i++)
    {
        cin>>vect_B[i];
    }
    cout << "Dot product : ";
    cout << dotProduct(vect_A, vect_B) << endl;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog