/  C Programs   /  C program to sort given array

C program to sort given array

#include<stdio.h> 
main()
{
int a[10],i,n,j,temp;
printf("enter the size of array: "); 
scanf("%d",&n);
printf("enter %d elements into array: ",n); 
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
for(j=i;j<n;j++)
{
if(a[i]>a[j])
{
temp=a[i]; 
a[i]=a[j]; 
a[j]=temp;
}
}
}
printf("the elements in sorted order: "); 
for(i=0;i<n;i++)
{
printf("%d\t",a[i]);
}
}

 

Output:

 

C program to sort given array

 

 

Leave a comment