/*PROGRAM TO SORT A GIVEN ARRAY USING SELECTION SORT*/
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,j,a[10],temp;
clrscr();
printf(“Enter the size of array: “);
scanf(“%d”,&n);
printf(“Enter %d elements in the array:\n”,n);
for(i=0;i<n;i++)
scanf(“%d”,&a[i]);
printf(“Array elements before sorting are:\n”);
for(i=0;i<n;i++)
printf(“%5d”,a[i]);
/*SORTING STARTS*/
for(i=0;i<n-1;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 after sorting are:\n”);
for(i=0;i<n;i++)
printf(“%5d”,a[i]);
getch();
}