Write the program of vector
and dot product using user defined function in c++
#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;
}
Comments
Leave a comment