There is a task to find the maximum and minimum element in the array, and swap them. I found such an example, but I don’t know how to output a modified array:
#include <iostream> /* run this program using the console pauser or add your own getch, system("pause") or input loop */ using namespace std; int main(int argc, char** argv) { int a; int N; int b; int c; int k; int g; int arr[N]; int max = arr[0]; int min = arr[0]; cout << "vvedit N="; cin >> N; cout << "vvedit massiv"; for (int i = 0; i < N; i++) { cin >> arr[i]; } for (int i = 0; i < N; i++) { if (max < arr[i]) { max = arr[i]; k = i; } if (min > arr[i]) { min = arr[i]; g = i; } } a = max = k; b = min = g; c = a; a = b; b = c; cout << "max=" << max << endl; cout << "min=" << min << endl; for (int i = 0; i < N; i++) { cout << arr[i]; } system("pause"); return 0;
min/maxinitialized before the array is entered? - Igorarr[???]=???(??? is the correct expression) so the array remains unchanged. You did not complete the task - you did not swap them. - nick_n_a