Laitofai

10

Apr 8th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. //10
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int n, mxIndex = 0, mnIndex = 0;
  9.     cin >> n;
  10.     int arr[n];
  11.     for(int i = 0; i < n; i++){
  12.         cin >> arr[i];
  13.         if(arr[i] > arr[mxIndex]){
  14.             mxIndex = i;
  15.         }
  16.         if(arr[i] < arr[mnIndex]){
  17.             mnIndex = i;
  18.         }
  19.     }
  20.     swap(arr[mxIndex], arr[mnIndex]);
  21.     for(int i = 0; i < n; i++){
  22.         cout << arr[i] << " ";
  23.     }
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment