Rotate your phone or change to desktop for better experience

Rotate your phone or change to desktop for better experience

DS || Pgm 7 || Program to sort the given list using selection sort technique.

 #include <stdio.h>

int main()

{

int arr[10];

int n;

int i, j, position, swap;

printf("Enter number of elements: ");

scanf("%d",&n);

printf("Enter the elements of array");

for(i=0;i<n;i++)

scanf("%d",&arr[i]);

for (i = 0; i < (n - 1); i++)

{

position = i;

for (j = i + 1; j < n; j++)

{

if (arr[position] > arr[j])

position = j;

}

if (position != i)

{

swap = arr[i];

arr[i] = arr[position];

arr[position] = swap;

}

}

for (i = 0; i < n; i++)

printf("%d\t", arr[i]);

return 0;

}

Post a Comment

0 Comments