-
Total time limit:
-
1000ms
-
Memory Limit:
-
65536kB
-
-
Describe
-
-
In linear algebra and computational geometry, the vector dot product is a very important operation.
Given two n-dimensional vectors a= (a1,a2,..., an) and b= (B1,b2,..., bn), find dot product a· b=a1b1+a2b2+...+anbn.
-
-
Input
-
-
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 is no more than 1000.
-
-
Output
-
-
an integer, which is the dot product result of two vectors.
-
-
Sample input
-
-
31 4 62) 1 5
-
-
Sample output
-
36
#include <stdio.h>intMain () {inta[ +]={0},b[ +]={0}; intsum=0; intn=0; scanf ("%d",&N); for(intI=0; i<=n-1; i++) {scanf ("%d",&A[i]); } for(intI=0; i<=n-1; i++) {scanf ("%d",&B[i]); } for(intI=0; i<=n-1; i++) {sum+=a[i]*B[i]; } printf ("%d", sum); return 0;}
09: Vector dot Product calculation