Sorting of array elements

Sorting of array elements :

 Arrays elements can be sorted in an ascending or descending order. 

main()
{
int a[50],i,j,n, temp;

printf("\n Enter the number of elements : ");
scanf("%d",&n);

printf("\nEnter the elements of array a - ");
for(i=0;i
{
  scanf("%d",&a[i]);
}

/*Sorting Process */
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;
      }
}


printf("\nElements of array are - \n ");
for(i=0; 
i < n; i++)
{
  printf("\n %4d",a[i]);
}

}

Comments