Write a c++ program to print the bubble sort

Write a c++ program to print the bubble sort. This is also sorting program to sort the numbers in C++ programming language. Bubble sorting is the important sorting method and most used sorting method in c++.

#include<iostream>
using namespace std;
int main()
{
int a[20],n,i,j,temp;
cout<<"Enter the size";
cin>>n;
cout<<"Enter the elements"; 
for(i=0;i<n;++i)
cin>>a[i];
for(i=1;i<n;++i)
{
for(j=0;j<(n-i);++j)
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
cout<<"After sorting";
for(i=0;i<n;++i)
cout<<" "<<a[i];
return 0;
}

 

Output:

Enter the size 3

Enter the elements 12 34 56

After sorting 12 34 56