Advertisement
PuffySheep

Lab 8

Nov 20th, 2014
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1.  
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. //function prototypes
  8.  
  9. int smallestIndex(int listArray[], int Size);
  10.  
  11. void main()
  12. {
  13.  
  14.     int listArray[10] = { 20, 67, 4, 38, 1, 63, 28, 95, 10, 7 };
  15.  
  16.     int location = smallestIndex(listArray, 10);
  17.  
  18.     cout << "The location of the smallest number in the list = " << location << endl;
  19.  
  20.  
  21.  
  22.    
  23. }
  24.  
  25.  
  26. //Function smallestIndex
  27. //smallestIndex finds the smallest number in the listArray and returns it
  28.  
  29. int smallestIndex(int listArray[], int Size)
  30. {
  31.  
  32.     int i;
  33.     int minIndex = 0;
  34.  
  35.     for (i = 1; i < Size; i++)
  36.     {
  37.         if (listArray[minIndex] > listArray[i])
  38.         {
  39.             minIndex = i;
  40.         }
  41.     }
  42.     return minIndex;
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement