Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- int N, min, max;
- cout << "Enter N: ";
- cin >> N;
- if (N <= 0 || N % 2 != 0) {
- cout << "N must be positive and even";
- return 0;
- }
- int* array = new int[N];
- cout << "Fill the array:" << endl;
- min = max = N / 2 - 1;
- for (int i = 0; i < N; i++) {
- cout << i + 1 << ") ";
- cin >> array[i];
- if (i < N / 2 - 1) {
- if (array[min] > array[i]) {
- min = i;
- }
- } else {
- if (array[i] > array[max]) {
- max = i;
- }
- }
- }
- int temp = array[max];
- array[max] = array[min];
- array[min] = temp;
- cout << endl
- << "Your array afer swapping min from first half to max from second:";
- for (int i = 0; i < N; i++) {
- cout << array[i] << ' ';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement