Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //10
- #include <iostream>
- using namespace std;
- int main()
- {
- int n, mxIndex = 0, mnIndex = 0;
- cin >> n;
- int arr[n];
- for(int i = 0; i < n; i++){
- cin >> arr[i];
- if(arr[i] > arr[mxIndex]){
- mxIndex = i;
- }
- if(arr[i] < arr[mnIndex]){
- mnIndex = i;
- }
- }
- swap(arr[mxIndex], arr[mnIndex]);
- for(int i = 0; i < n; i++){
- cout << arr[i] << " ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment