#include <iostream>
using namespace std;
int main()
{
const int n = 20;
int Array[n] = { 3, 5, 2, 9, 6, 12, 16, 11, 18, 4, 14, 8, 1, 15, 17, 7, 19, 13, 20, 10 };
cout << "Not sorted: \n";
for (int i = 0; i < n; ++i)
{
cout << Array[i] << " ";
}
cout << endl;
for (int i = 0; i < n; ++i)
{
for (int j = n - 1; j > i; --j)
{
if (Array[j] < Array[j - 1])
{
int temp = Array[j];
Array[j] = Array[j - 1];
Array[j - 1] = temp;
}
}
}
cout << "Sorted: \n";
for (int i = 0; i < n; ++i)
{
cout << Array[i] << " ";
}
cout << endl;
system("pause");
return 0;
}
Njay19 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.