0
#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;
}
2
Contributors
2
Replies
15
Views
2 Years
Discussion Span
Last Post by Njay19
0

The code you have posted compiles fine (except that to use system, you should #include <cstdlib>). Whatever code you have that produces the error you mentioned is not this code.

Edited by Moschops

0

Ok thanks, it was doing the same for my older codes that worked previously

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.