Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a C function named square_reverse with three parameters. The two first pa

ID: 2267004 • Letter: C

Question

Create a C function named square_reverse with three parameters. The two first parameters are 64-bit floating-point pointers x and y, and the third parameter is an integer parameter called len. The function must not return any value. Pointer x points to an array of length len of floating-point values. The function reads out each element of the array, computes the square value of the element (x2) and then writes back the result into the array y in reverse order. That is, the output array y has also the length len. For example, if we have the following declarations double in[] = {11.0, 20.0, 100.0); double out [3] a function call square_reverse (in,out, 3); should result in that the three ele- ments 10000.0, 400.0, and 121.0 are the content of out. Note that your function should also declare parameters as const when appropriate. Your solution:

Explanation / Answer

void reverse_array(float *x, float *y, const int len)
{
   int c, d;
   int j;
    for (j = 0; j < len; j++) //computing the square of the input array
        x[j]=x[j] * x[j];

   s = (int*)malloc(sizeof(int)*n);

   if( s == NULL )
      exit(EXIT_FAILURE);

   for ( c = len - 1, d = 0 ; c >= 0 ; c--, d++ ) // reversing the array to the new array y
      *(y+d) = *(pointer+c);

free(s);
}