/*Write a C++ program to sort the elements of the array.*/
#include<iostream.h>
#include<conio.h>
void main( )
{
int a[50], i, temp, n, j;
clrscr( );
cout<<"Enter the number of elements:";
cin>>n;
cout<<"Enter the elements:\n";
for(i=0; i<n; i++)
cin>>a[i];
for(i=0; i<n; i++)
for(j=i+1; j<n; j++)
if(a[i] > a[j])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
cout<<"The sorted elements are:\n";
for(i=0; i<n; i++)
cout<<a[i]<<"\n";
getch( );
}

No comments: