- #include
-
- #define compute(x, y, n)\
- ({\
- int sum_tmp = 0;\
- for (int i = 0; i < n; ++i)\
- sum_tmp += x[i] * y[i];\
- sum_tmp;\
- })
-
-
- int dotProduct(int x[], int y[], int n)
- {
- int i, sum;
-
- sum = compute(x, y, n);
-
- return sum;
- }
-
- int main(void)
- {
- int x[] = {1, 2};
- int y[] = {3, 4};
-
- int result = dotProduct(x, y, 2);
-
- printf("%d\n", result);
-
- return 0;
- }