Explore BrainMass

Explore BrainMass

    Find the Largest and Smallest and Sort values in array C++

    Not what you're looking for? Search our solutions OR ask your own Custom question.

    This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

    Write two function in C++ with using arrays to find largest and smallest number.
    For example you have 1,43,42,9,8,5. You need arrange them smallest to highest and highest to smallest.

    © BrainMass Inc. brainmass.com March 4, 2021, 6:46 pm ad1c9bdddf
    https://brainmass.com/computer-science/cpp/60920

    Solution Preview

    Two functions: findMin() and findMax() have been coded and tested in main().
    Please find the code, Arr1.cpp and executable Arr1.exe attached.
    The code is explained with comments. You should be able to use the ...

    Solution Summary

    Two functions: findMin() and findMax() have been coded and tested in main().
    Please find the code, Arr1.cpp and executable Arr1.exe attached.
    The code is explained with comments. You should be able to use the two functions to achieve what you want including sorting of an array.

    For sorting, you need to do a little bit more than just finding minimum and maximum from an array. Simply finding the smallest and/or largest does not automatically lend itself to a sorted array.
    Specifically, for an array containing positive integers, you need to repeatedly find the largest number (or smallest number) from the array, print it and replace that largest number with a (say ) negative number, so that it doesn't get picked again in the next iteration. Continue doing this for n elements, where n is the length of the array.

    $2.49

    ADVERTISEMENT