Write a ‘C’ Program to sort elements of an array in ascending order using dynamic memory allocation


#include<stdio.h>
#include<conio.h>
#include<alloc.h>
void main()
 {
 int a[5];
 int i,j,n,temp;
 clrscr();
 printf("\n enter the limit of array");
 scanf("\n %d",&n);
a[i]=(int) calloc(n,sizeof(int));
 printf("\n enter the array element");
 for(i=0;i<n;i++)
  {
  scanf("\n %d",&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;
             }}}
   printf("\n the asending elements are");
   for(i=0;i<n;i++)
            {
            printf("\n %d",a[i]);}
   getch();
  }
/* output

 enter the limit of array5

 enter the array element 56  8 34 1 78
 the asending elements are
 1
 8
 34
 56
 78
*/