#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;
}

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.

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

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.