BUBBLE SORT

#include<iostream>
using namespace std;
void swap(int &x,int &y)
{
    x=x+y;
    y=x-y;
    x=x-y;
}
int main()
{
    cout<<"how many number:";
    int n;
    cin>>n;
    cout<<"enter the no"<<endl;
    int a[20];
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<n-1;i++)
    {
        for(int j=0;j<n-1;j++)
        {
            if(a[j]>a[j+1])
                swap(a[j],a[j+1]);
        }
    }
    cout<<"after sorting\n";
    for(int i=0;i<n;i++)
        cout<<a[i]<<endl;
        return 0;
}

Total Pageviews