Saturday, 27 July 2013

Write a Program Bubble Sort using Sorting Algorithm in C++ Language

#include<iostream.h>
#include<conio.h>
int main()
{
           int arr[5],i,j,temp;
           cout<<"Enter the element of Array:";
           for(i=0;i<5;i++)
           {
                    cin>>arr[i];
           }

           cout<<"Array are Sorted:";
           for(i=0;i<5;i++)
           {
                      for(j=o;j<4-i;j++)
                      {
                                  if(arr[j]<arr[j+1)
                                  {
                                              temp=arr[j];
                                              arr[j]=arr[j+1];
                                              arr[j+1]=temp;
                                  }
                      }
                    cout<<arr[j];
            }

         getch();
         return 0;
}



Output : 

Enter the element of Array:2
8
9
4
6

Array are Sorted :24689

0 comments:

Post a Comment

Followers