Hi,
This code is supposed to calculate the dot product of two 3-dimensional vectors.
I get syntax error in line 29. (syntax error before ']' token)
Code:
#include<stdio.h>
#include<stdbool.h>
#include<stdlib.h>
/* UTILITIES */
#define MAX 3
float dot_prod(float v1[], float v2[]);
/* MAIN */
int main()
{
int i;
float v1[MAX],
v2[MAX],
result;
printf("Enter the first vector\n");
for (i=0; i<MAX ; i++){
printf(":");
scanf("%f",&v1[i]);
}
printf("Enter the second vector\n");
for (i=0; i<MAX ; i++){
printf(":");
scanf("%f",&v2[i]);
}
result=dot_prod(v1[], v2[]); /* Line 29 */
printf("%f",result);
return 0;
}
/* DEFINITION */
float dot_prod(float v1[], float v2[]){
int i;
float a,
b,
tot,
total=0;
for(i=0;i<MAX;i++){
a=v1[i];
b=v2[i];
tot=a*b;
total=total + tot;
}
return total;
}