#include <iostream>
signed main() {
setlocale(LC_ALL, "Rus");
const int size = 10;
int arr[size];
std::cout << "Исходный массив: ";
for (int i = 0; i < size; ++i) {
arr[i] = rand() % 10;
std::cout << arr[i] << " ";
}
int k = 0;
for (int i = 0; i < size - 1; i++)
{
k = i + 1;
int temp = arr[k];
for (int j = i + 1; j > 0; j--)
if (temp < arr[j - 1])
arr[j] = arr[j - 1];
k = j - 1;
arr[k] = temp;
std::cout << "\nОтсортированный массив: ";
return 0;
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
#include <iostream>
signed main() {
setlocale(LC_ALL, "Rus");
const int size = 10;
int arr[size];
std::cout << "Исходный массив: ";
for (int i = 0; i < size; ++i) {
arr[i] = rand() % 10;
std::cout << arr[i] << " ";
}
int k = 0;
for (int i = 0; i < size - 1; i++)
{
k = i + 1;
int temp = arr[k];
for (int j = i + 1; j > 0; j--)
{
if (temp < arr[j - 1])
{
arr[j] = arr[j - 1];
k = j - 1;
}
}
arr[k] = temp;
}
std::cout << "\nОтсортированный массив: ";
for (int i = 0; i < size; ++i) {
std::cout << arr[i] << " ";
}
return 0;
}