C++ Program to implement Bubble Sort.

Program:

#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();
int array[30],N,temp;
cout<<"Enter number of elements: ";
cin>>N;
for(int i=0;i<N;i++)
       { cout<<"Enter number "<<i+1<<": ";
     cin>>array[i];
       }

       for(i=0;i<N-1;i++)
     for(int j=0;j<N-1-i;j++)
       if(array[j]>array[j+1])
     {
temp = array[j];
array[j]=array[j+1];
array[j+1]=temp;
     }

    cout<<"Sorted Numbers are: \n";
for(i=0;i<N;i++)
  cout<<array[i]<<endl;

getch();
}
Share this post
  • Share to Facebook
  • Share to Twitter
  • Share to Google+
  • Share to Stumble Upon
  • Share to Evernote
  • Share to Blogger
  • Share to Email
  • Share to Yahoo Messenger
  • More...
 
Posts RSSComments RSSBack to top
© 2013 Updated Tech News Results and Reviews