C++ Bubble Sort

#include<iostream>
using namespace std;
int main()
{
    int n, i, j;

    cout << "Enter Array Element Number :: ";
    cin >> n;
    cout << endl;

    int a[n];

    cout << "Enter Array Element :: ";
    for(i=0;i<n;i++)
    {
        cin >> a[i];
    }
    cout << endl;

    for(i=0;i<n-1;i++)
    {
        for(j=0;j<n-i-1;j++)
        {
            if(a[j] > a[j+1])
            {
                swap(a[j], a[j+1]);
            }
        }
    }

    cout << "Ascending Order :: ";
    for(i=0;i<n;i++)
    {
        cout << a[i] << " ";
    }
    cout << endl;

    return 0;
}

Comments