Friday, May 03, 2013

bubble sort in C++


#include<iostream>
using namespace std;
int main()
{
   
    int n,p;
    cout<<"enter the array length: ";
    cin>>n;
    int bc[n];
      for(int i=0;i<=n;i++)
    {
            cout<<"the value of bc["<<i<<"] is: ";
    cin>>bc[i];
}
for(int k=1;k<=n-1;k++)
{
       
        for(int p=1;p<=n-k;p++)
        {if(bc[p]>bc[p+1])
        bc[p]=bc[p+1];
}
}
for(int i=0;i<=n;i++)
    {
            cout<<"the value of bc["<<i<<"] is:"<<bc[i]<<endl;
            }
}

No comments:

Post a Comment