C Program to Sort an array in Ascending Order

#include<stdio.h>
#include<conio.h>
void main()
{
 int x[100],y,j,i,v;
 clrscr();
 printf("Enter size of array:- ");
 scanf("%d",&y);
 printf("Enter Elements in array:- \n");
 for(i=0;i<y;i++)
 {
  scanf("%d",&x[i]);
 }
 for(i=0;i<y;i++)
  {
     for(j=i+1;j<y;j++)
      {
       if(x[i]>x[j])
	{
	 v=x[j];
	 x[j]=x[i];
	 x[i]=v;
	}
      }
  }
 printf("Sorted array is:- \n");
 for(i=0;i<y;i++)
  {
   printf("%d\n",x[i]);
  }

 getch();
}

OUTPUT:-

sort

Leave a Reply

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