Question: val_ref.c #include #include #include #include libsquare.h int main() { int* array1; int* array2; int* array3; int size; //prompt for array size printf(Enter the array size:

val_ref.c
#include
int main() { int* array1; int* array2; int* array3; int size;
//prompt for array size printf("Enter the array size: "); scanf("%d", &size);
//allocate memory for both arrays array1 = (int*) malloc(size * sizeof(int)); //will be used with square_val() array2 = (int*) malloc(size * sizeof(int)); //will be used with square_ref() array3 = (int*) malloc(size * sizeof(int)); //will be used with square_arr()
//scan the array printf("Enter %d integers: ", size); for (int c = 0; c
memcpy(array2, array1, size * sizeof(int)); memcpy(array3, array1, size * sizeof(int));
for(int c = 0; c
//print array1[ ] printf("Array1 squared by value: "); for(int c = 0; c
//print array2[ ] printf(" Array2 squared by reference: "); for(int c = 0; c
//print array3[ ] printf(" Array3 squared by array pointer: "); for(int c = 0; c 1) Write two fimctions that square the elements in an integer array of a given size. One of the functions returns the squared value of a single eleent every time it is called, and the other function operates on a pointer (there is no returned vae). Now, write a third function that takes in an int pointer (will point to an int array) and an int for the size of the array This third function will square all the elements in the given array when it is called. You must write your own libsquare.h that contains the prototypes of the three aforementioned square functions, and libsquare.c that contains the function definitions. The main souo C file is given to you in a file named valref.c to test your fnctions, do not change anything in this file. The following prototypes must be included in libsquare.h: int square val (int element) void square.ref(int element) void square arr (int * array, int size); The output of your code shoud appear as follows: Enter the array size Enter 5 integers -1 35 2 4 Arrayl squared by value 19 25 4 16 Array2 squared by reference 19 25 4 16 Array3 squared by array pointer 19 25 4 16 To compile your oode, remember that you mist compile both val ref.c and libsquare.c but not libsquare.h. In other words, run 'gcc val.ref.c li bsquare.c Note: Do not se the math.h library. You only need to submit your libsquare.c and libsquare.h fies in your tar
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
