Description: A Program to illustrate Bubble Sort in an array.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,n,a[20],j,temp=0;
cout<<"Enter the no of elements in array";
cin>>n;
cout<<"Enter array";
for(i=0;i<n;i++)
cin>>a[i];
for(i=0;i<n;i++)
{ for(j=0;j<n-i-1;j++)
{ if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
cout<<"sorte array is:\n";
for(i=0;i<n;i++)
cout<<a[i]<<",";
getch();
}
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,n,a[20],j,temp=0;
cout<<"Enter the no of elements in array";
cin>>n;
cout<<"Enter array";
for(i=0;i<n;i++)
cin>>a[i];
for(i=0;i<n;i++)
{ for(j=0;j<n-i-1;j++)
{ if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
cout<<"sorte array is:\n";
for(i=0;i<n;i++)
cout<<a[i]<<",";
getch();
}
Please LIKE & SHARE US if you find this helpful!
0 comments:
Post a Comment