Fine Min between subarray


/ Published in: C++
Save to your folder(s)

Write function "get_min_range" 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.


Copy this code and paste it in your HTML
  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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.