当前位置:网站首页>-Vector Dot Product-

-Vector Dot Product-

2022-08-10 01:46:00 -JMY-

Title description

Vector dot product is a very important operation in linear algebra and computational geometry.

Given two n-dimensional vectors a=(a1,a2,...,an) and b=(b1,b2,...,bn), find the dot product a·b=a1b1+a2b2+...+anbn.

Enter

The first line is an integer n.1 <= n <= 1000.
The second line contains n integers a1,a2,...,an.
The third line contains n integers b1,b2,...,bn.
Adjacent integers are separated by a single space.The absolute value of each integer does not exceed 1000.

Output

An integer, the result of the dot product of two vectors.

Sample input

31 4 62 1 5

Sample output

36

Reference code:

#include
using namespace std;
int n,a[1005],b[1005],s;
int main(){
scanf("%d",&n);
for(int i=0;i scanf("%d",a+i);
for(int i=0;i scanf("%d",b+i);
for(int i=0;i s+=a[i]*b[i];
printf("%d",s);
return 0;
}

原网站

版权声明
本文为[-JMY-]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/222/202208092346036996.html