67.0k views
3 votes
Write a program that implement a bubble sort ?

1 Answer

3 votes

Answer:

A program that implement a bubble sort:

#include<iostream.h>

#include<conio.h>

int main()

{

int ar[50],no,i,j,temp;

cout<<"Enter array size ";

cin>>no;

cout<<"Enter array elements ";

for(i=0;i<no;++i)

cin>>ar[i];

for(i=1;i<no;++i)

{

for(j=0;j<(no-i);++j)

if(ar[j]>ar[j+1])

{

temp=ar[j];

ar[j]=ar[j+1];

ar[j+1]=temp;

}

}

cout<<"Bubble Sort array";

for(i=0;i<no;++i)

cout<<" "<<ar[i];

return 0;

}

User Blake Bowen
by
8.3k points