HTML & JS
#include<stdio.h>
void main()
{
  int a[10]={12, 78,1, 10, 34};
  int n=5;
  int b;
  printf("The elements are:");
  for(int i=0;i<n;i++)
      printf("%d ",a[i]);

  //ascending order
  for(int i=0;i<n;i++)
  {
     for(int j=i+1;j<n;j++)
         if(a[i]>a[j])
         {
             b=a[i];
             a[i]=a[j];
             a[j]=b;
         }
  }
  printf("\nSorted array in ascending order:");
  for(int i=0;i<n;i++)
    printf("%d ",a[i]);
    
  //descending order    
  for(int i=0;i<n;i++)
  {
     for(int j=i+1;j<n;j++)
         if(a[i]<a[j])
         {
             b=a[i];
             a[i]=a[j];
             a[j]=b;
         }
  }
  printf("\nSorted array in descending order:");
  for(int i=0;i<n;i++)
    printf("%d ",a[i]);
}

Generated URL:

Output:

The elements are:12 78 1 10 34 
Sorted array in ascending order:1 10 12 34 78 
Sorted array in descending order:78 34 12 10 1 
Report Bug