Write a program that generates an array of 15 random numbers from -20 to 20 and swaps the value

Write a program that generates an array of 15 random numbers from -20 to 20 and swaps the value of the first of the last elements of the array.

#include <iostream>
#include <vector>
#include <ctime>
using namespace std;
int main () {
// Create a program that generates an array of 15 random numbers from – 20 to 20 and swaps the value of the first and last elements of the array
srand (time (NULL)); // for a random number generator
vector <int> arr;
int n = 15;
for (int i = 0; i <n; i ++) {
arr.push_back (rand ()% 41 – 20);
cout << arr [i] << ”; // display an array with numbers
}
cout << endl;
int temp = arr [0]; // replace the first and last element
arr [0] = arr [n – 1];
arr [n – 1] = temp;
for (auto now: arr) // output the resulting array
cout << now << “”;
cout << endl;
system (“pause”);
return 0;
}



One of the components of a person's success in our time is receiving modern high-quality education, mastering the knowledge, skills and abilities necessary for life in society. A person today needs to study almost all his life, mastering everything new and new, acquiring the necessary professional qualities.