Posted By

itsaboutcode on 11/10/10


Tagged

array c++ mixmin


Versions (?)

Fine Min between subarray


 / Published in: C++
 

URL: http://www.cramster.com/answers-nov-10/computer-science/arrays-write-function-quotget-min-rangequot-returns_1027784.aspx

Write function "getminrange" which returns the subscript of the smallest value in a portion of an array containing type int values. It has three arguments: an array, the first subscript in the subarray, and the last subscript in the subarray.

  1. int get_min_range(int array[], int firstSubscript, int lastSubscript)
  2. {
  3. int smallestValue = array[firstSubscript];
  4. int smalledIndex = firstSubscript;
  5. for (int i = firstSubscript; i <= lastSubscript; i++)
  6. {
  7. if (array[firstSubscript] < smallestValue)
  8. {
  9. smallestValue = array[firstSubscript];
  10. smalledIndex = firstSubscript;
  11. }
  12. }
  13. return smalledIndex;
  14. }

Report this snippet  

You need to login to post a comment.