Selection Sort program in C Language

Selection Sort program in C Language algorithm implementation – selection sort is it never makes more than O(n) swaps and can be useful when memory write is a costly operation.

  • Time Complexity: O(n2)
  • Auxiliary Space: O(1)

In this program user would be asked to enter the number of elements along with the element values and then the programs would sort them in ascending order by using merge sorting algorithm logic.

Types of Sorting Algorithms:

<img width=

Selection Sort algorithm C Program implementation

#include <stdio.h>
int main() {
   int arr[10]={5,11,1,19,12,100,56,46,35,3};
   int n=10;
   int i, j, position, swap;
   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;


1 3 7 12 13 19 35 46 56 100

Additional Reading

you can read more articles like this here.


If you found this post useful, don’t forget to share this with your friends, and if you have any query feel free to comment it in the comment section.❤

Leave a Reply