-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector.cpp
More file actions
49 lines (41 loc) · 679 Bytes
/
Copy pathvector.cpp
File metadata and controls
49 lines (41 loc) · 679 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include<iostream>
using namespace std;
struct vector
{
int index;
int val;
}A[10],B[10];
int main()
{
int product=0,i=0,j=0;
cout<<"Enter nonzero elements in A"<<endl;
cout<<"Index val"<<endl;
for (int i=0; i<4; i++)
{
cin>>A[i].index>>A[i].val;
}
cout<<"Enter nonzero elements in B"<<endl;
cout<<"Index val"<<endl;
for (int i=0; i<3; i++)
{
cin>>B[i].index>>B[i].val;
}
//Computing the dot product of the vector arrays
for(int i=0;i<10;i++)
{
for(int j=0;j<10;j++)
{
if(i==j)
{
product+=(A[i].val*B[j].val);
i++;
j++;
}
else if(i<j)
{
i++;
}
}
}
cout<<"Dot-product AB is "+product<<endl;
}