※以下のソースコードはコピー防止の対応をしています.
01: #include <stdio.h>
02: #include <math.h>
03:
04: #define LEN 4
05:
06: float inner_product(float a[], float b[]);
07: float vabs(float a[]);
08:
09: int main(void)
10: {
11: float a[LEN], b[LEN];
12: int i;
13:
14: for(i = 0; i < LEN; i++){
15: printf("a[%d]=", i);
16: scanf("%f", &a[i]);
17: }
18:
19: for(i = 0;i < LEN; i++){
20: printf("b[%d]=", i);
21: scanf("%f", &b[i]);
22: }
23:
24: printf("inner product <a, b> = %f\n", inner_product(a, b));
25: printf("absolute value |a| = %f\n", vabs(a));
26:
27: return 0;
28: }
29:
30: float inner_product(float a[], float b[])
31: {
32: int i;
33: float val = 0;
34:
35: for(i = 0; i < LEN; i++){
36: val += a[i] * b[i];
37: }
38: return val;
39: }
40:
41: float vabs(float a[])
42: {
43: return sqrt(inner_product(a, a));
44: }