Advertisement
Guest User

MinMaxVector

a guest
Jul 20th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4. int main()
  5. {
  6.    
  7.     vector <int> vertices;
  8.     int n=12,k, max,min, MaxIndex, MinIndex;
  9.    
  10.    
  11.     while (n!=0)
  12.     {
  13.         cin>>n;
  14.         vertices.push_back(n);
  15.        
  16.     }
  17.     k=vertices.size();
  18.    
  19.     max=vertices[0];
  20.     min=vertices[0];
  21.    
  22.     for (int i=1; i<k; i++)
  23.     {
  24.         if(vertices[i]>max)
  25.         {
  26.             max=vertices[i];
  27.             MaxIndex=i;
  28.         }
  29.         if(vertices[i]<min)
  30.         {
  31.             min=vertices[i];
  32.             MinIndex=i;
  33.         }
  34.     }
  35.    
  36.     cout<<"max = "<<max<<", with index "<<MaxIndex<< endl;
  37.     cout<<"min = "<<min<<", with index "<<MinIndex<<endl;
  38.    
  39.    
  40.      return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement