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

Write and test a function that is passed an array of n integers and returns a po

ID: 3790740 • Letter: W

Question

Write and test a function that is passed an array of n integers and returns a pointer to the array cell that has the maximum value among the n integers. The function must use the travelling pointer (1st version) notation to traverse the array. The function has the following prototype. int* maximum ( int *p , int n); 3. Write and test a function that is passed an array of n integers and returns a pointer to the array cell that has the maximum value among the n integers. The function must use the travelling pointer (1st version) notation to traverse the array. The function has the following prototype. int maximum (int *p, int n);

Explanation / Answer

int* maximum(int *p, int n)

{

int max = *p; // set max to first element of the array

for(int j = 1; j < n; j++) // loop till n integers

{

p++; // move pointer to next element

if(*p > max) // if new element is maximum than stored max // // value, then new value is set to max

{

max = *p;

}

}

return max; // max will contain maximum value in the array

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote