-3
int Dot_Product( int A[], int B[], int size )
{ 
     int i = 0;
     int P[size];

     while ( i <= size ) {
         P[i] = A[i] * B[i];
     }

     return P;   
}
MAV
  • 7,260
  • 4
  • 30
  • 47
user3019432
  • 21
  • 1
  • 3

2 Answers2

1

You can't return arrays in C. You can return pointers to arrays but then you have to worry about memory management. So often, people pass arrays INTO the function to be used for assignment.

However if you're really just trying to take the dot product, you shouldn't end up with an array, you should end up with a single value, so this should suffice:

    int Dot_Product( int A[], int B[], int size )
    { 
        int i = 0;
        int product = 0;
        while ( i < size ){
            product += A[i] * B[i];
            ++i;
        }
        return product;   
     }
Taylor Brandstetter
  • 3,523
  • 15
  • 24
0

C doesn't allow you to return arrays, you can pass a pointer to a function and with that pointer change the values of the array you declare in the main function.

void Dot_Product(int A[], int B[], int size, int *product) {
int i;
for(i=0; i<size; i++) 
   product[i]=A[i]*B[i];
}