#include <stdio.h> #include <stdlib.h> #define MAX_INDEX 5 int main() { /*prototype of the function*/ float Scalar_Product(int, float[], float[]); int n,i; float x[MAX_INDEX], y[MAX_INDEX]; printf("\n Vector dimension n="); scanf("%d",&n); if(n < 1 || n > MAX_INDEX) { printf("\n Error in input data!"); exit(1); } printf("Input %d coordinate x: ", n); for (i=0; i<n; i++) scanf("%f", &x[i]); printf("Input %d coordinate y: ", n); for (i=0; i<n; i++) scanf("%f", &y[i]); printf("\n Result: %7.3f \n", Scalar_Product(n,x,y)); exit(0); } /* --- The scalar product function ---------*/ float Scalar_Product(int n, float a[], float b[]) /* n - dimension of the vectors */ /* a[], b[] - the vector coordinates */ { int i; double z; for (i=0,z=0.0; i < n; i++) z += a[i]*b[i]; return z; }