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

Please write program in C. 1. Arrays In this exercise you will write several fun

ID: 3729002 • Letter: P

Question

Please write program in C.

1. Arrays In this exercise you will write several functions that operate on arrays. You will place all the function prototypes in a header file named array utils.h with their definitions in a source file named arrayutils.c. You should test your functions by writing a driver program, but you need not hand it in. (a) Write a function that takes an integer array and returns the sum of its elements between two given indices, i, j int subSum (const int *a, int size, int i, int j); (b) Write a function that takes an integer array and returns the sums all of its elements int sum(const int *a, int size); (c) In an array, a contiguous subarray consists of all the elements between two indices i,j; the sum of the subarray is the sum of all the elements between i,j. The marimum contiguous subarray problem is the problem of finding the i,j whose subarray sum is maximal (it may not be unique). Write a function that takes an integer array and returns the sum of the maximum contiguous subarray. int maxSubArraySum (const int *a, int size); (d) Write a function that, given an integer array and an integer r determines if the array contains r within two provided indices, i,j int containsWithin(const int *a, int size, int x, int i, int j); (e) Write a function that, given an integer array and an integer x determines if the array contains r anywhere within the array. int contains (const int *a, int size, int x); (f) Write a function that takes two integer arrays and determines if they are equal that is, each index contains the same element. If they are equal, then you should return true (non-zero), if not return false (zero) int isEqual (const int *a, const int *b, int size); (g) Write a function that takes two integer arrays and determines if they both contain the same elements (though are not necessarily equal) regardless of their multiplic- ity. That is, the function should return true even if the arrays' elements appear a different number of times (for example, 2, 2, 3 would be equal to an array containing 3, 2,3, 3, 3, 2,2,2) int containsSameElements (const int *a, int sizeOfA, const int *b, int size0fB)

Explanation / Answer

int Subsum(int *a,int size,int i,int j){

int k=0;

int sum = 0;

for(k=i;k<=j;k++){

sum+=a[k];

}

return sum;

}

int sum(int *a,int size){

int i=0;

int sum=0;

for(i=0;i<size;i++)sum+=a[i];

return sum;

}

int containsWithin(int *a,int size,int x,int i,int j){

int k=0;

for(k=i;k<=j;k++){

if(a[k]==x)return 1;

}

return 0;

}

int contains(int *a,int x,int size){

for(int i=0;i<size;i++){

if(a[i]==x)return 1;

}

return 0;

}

int isEqual(int *a,int *b,int size){

for(int i=0;i<size;i++){

if(a[i]!=b[i])return 0;

}

return 1;

}