Write a C function minimum This function is passed a vector

Write a C++ function minimum. This function is passed a vector parameter and returns the smallest value stored in the array list. Write an additional code fragment to test this function. Include any declarations and initialization statements necessary to test the function.

Solution

//Function to find minimum value in array
int min(apvector<int> &array)
{
     int length = array.length( );  // establish size of array
     int min = array[0];       // start with min = first element

     for(int i = 1; i<length; i++)
     {
          if(array[i] < min)
                min = array{i};
     }
     return min;                // return minimum value in array
}

------------------------------

Result look like this

Write a C++ function minimum. This function is passed a vector parameter and returns the smallest value stored in the array list. Write an additional code fragm

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site