#include <iostream>
using namespace std;
int main()
{
setlocale(LC_ALL, "russian");
int n = 20;
int* mas;
mas = new int[n];
for (int i = 0; i < n; i++)
mas[i] = rand() % 10;
cout << mas[i] << " ";
}
cout << endl;
for (int i = 0; i < n - 1; i++)
int min = i;
for (int j = i + 1; j < n; j++)
if (mas[j] < mas[min])
min = j;
swap(mas[i], mas[min]);
int sum = 0;
for (int i = n-5; i < n ; i++)
sum += mas[i];
cout << endl << " sum=" << sum;
Объяснение:
#include <iostream>
using namespace std;
int main()
{
setlocale(LC_ALL, "russian");
int n = 20;
int* mas;
mas = new int[n];
for (int i = 0; i < n; i++)
{
mas[i] = rand() % 10;
cout << mas[i] << " ";
}
cout << endl;
for (int i = 0; i < n - 1; i++)
{
int min = i;
for (int j = i + 1; j < n; j++)
if (mas[j] < mas[min])
min = j;
swap(mas[i], mas[min]);
}
for (int i = 0; i < n; i++)
{
cout << mas[i] << " ";
}
cout << endl;
int sum = 0;
for (int i = n-5; i < n ; i++)
{
sum += mas[i];
}
cout << endl << " sum=" << sum;
}
Объяснение: