Есть код:
#include<iostream>
#include<ctime>
using namespace std;
int main() {
setlocale(LC_ALL, "rus");
srand(time(NULL));
int arr[15];
cout << "Неотсортированный массив из 15 случайных чисел: { ";
for (int i = 0; i < 15; i++) {
arr[i] = 0 + rand() % (20) - 10;
cout << arr[i] << " ";
}
cout <<"}"<< endl;
cout << "Отсортированный массив: [ ";
for (int i = 0; i < 15; i++)
{
for (int j = i+1; j < 15; j++)
{
if (arr[i] > arr[j]) {
swap(arr[i], arr[j]);
}
}
}
for (int i = 0; i < 15; i++)
cout << arr[i]<<" ";
cout << "]" << endl;
return 0;
}
Задание: числа в массиве - рандомные, нужно их отсортировать так: сначала отрицательные на уменьшение, потом положительные на уменьшение.
У меня только по возрастанию сортировать получаеться(
Please enter comments
Please enter your name.
Please enter the correct email address.
You must agree before submitting.

Answers & Comments


Copyright © 2024 SCHOLAR.TIPS - All rights reserved.