C++ Program to sort elements of one dimensional array

Spread the love..

#include<iostream>
using namespace std;
int main()
{
  int a[10];
  int i,n,j,t;
  cout<>n;
  cout<<"nEnter elements in Array :";
for(i=0;i<n;i++)
   cin>>a[i];
for(i=0;i<n-1;i++)
{
  for(j=0;ja[j+1])
  {
    t=a[j];
    a[j]=a[j+1];
    a[j+1]=t;
  }
 }
}
cout<<"nSorted array is:=";
for(i=0;i<n;i++)
  cout<<endl<<a[i];
return 0;
}

Spread the love..

Leave a Reply

Your email address will not be published. Required fields are marked *