Bubble sorting is nothing but sorting n numbers in ascending order or descending order
Code
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[100], i, j, n, temp;
cout<<"Enter the size of the array";
cin>>n;
cout<<"Enter the elements in the array ";
for(i=0;i<n;++i)
cin>>a[i];
for(i=0;i<n;++i)
{
for(j=0;j<(n-1);++j)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
cout<<"\n Array after sorting in ascending order ";
for(i=0;i<n;++i)
cout<<a[i]<<" ";
}
0 comments:
Post a Comment