Write and test a function that is passed an array of n integ

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);

Solution

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

}

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 fun

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site