Input : 6 1 0 4 2
Output : 0 1 2 4 6
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
selectionSort(int a[], int n);
int main()
{
int a[20], i, n;
printf("Enter the size of Array : ");
scanf("%d", &n);
printf("Enter the array element : \n");
for (i = 0; i < n; i++)
{
printf("Array index[%d] : ", i);
scanf("%d", &a[i]);
}
selectionSort(a, n);
for (i = 0; i < n; i++)
{
printf("\t%d", a[i]);
}
getch();
return 0;
}
selectionSort(int a[], int n)
{
int temp, temp1, i, j;
for (i = 0; i < n; i++)
{
temp = a[i];
for (j = i + 1; j < n; j++)
{
if (a[j] < temp)
{
temp1 = temp;
temp = a[j];
a[j] = temp1;
}
a[i] = temp;
}
}
}
0 Comments