Selection Sort Program in C Programming | DSA Tutorials YASH PAL, 8 May 20268 May 2026 To program the selection sort algorithm in C programming, we first need to understand how selection sort works. The selection sort starts from the first element and searches the entire list until it finds the minimum value. The sort places the minimum value in the first place, selects the second element and searches for the second smallest element. The process continues until the complete list is sorted.A selection sort is one in which successive elements are selected in order and placed into their proper sorted positions. The selection process needs to be done only from 1 to n-1 rather than up to n. Analysis of the selection sort is straightforward. The first pass makes n-1 comparisons, the second pass makes n-2 and so on. So total comparisons are (N-1) + (N-2) + (N-3) + … + 2 + 1 = N (N-1)/2 = O(N2).If you want a working example of the selection sort algorithm with a step-by-step explanation, then read this tutorial – Selection Sort Algorithm Example.Let’s see the two different implementations of the selection sort algorithm in C programming.Selection sorting (First logic) Program in C#include<stdio.h> #include<conio.h> #define SIZE 10 void selection_sort(int [], int); void main() { int a[SIZE],i,n; printf("Enter how many elements "); scanf("%d",&n); /*Input Array*/ for(i=0;i<n;i++) { printf("Enter element %d ",i+1); scanf("%d",&a[i]); } selection_sort(a,n); /*Output Array */ for(i=0;i<n;i++) printf("%d",a[i]); getch(); } void selection_sort(int a[], int n) { int i,j,t,min,minpos; for(i=0;i<n-1;i++) { min = a[i]; minpos = i; for(j=i+1; j<n; j++) { if(a[j] < min) { min = a[j]; minpos = j; } } if( i != minpos) { t = a[i]; a[i] = a[minpos]; a[minpos] = t; } } }OutputEnter how many elements 6 Enter element 1 200 Enter element 2 140 Enter element 3 50 Enter element 4 60 Enter element 5 90 Enter element 6 77 50 60 77 90 140 200 Selection sorting (Second Logic) C Program#include<stdio.h> #include<conio.h> #define SIZE 10 void selection_sort(int [], int); void main() { int a[SIZE],n,i; printf("Enter how many elements "); scanf("%d",&n); /*Input array */ for(i=0;i<n;i++) { printf("Enter element %d ",i+1); scanf("%d", &a[i]); } selection_sort(a,n); /*Output array */ for(i=0;i<n;i++) printf("%d ",a[i]); getch(); } void selection_sort(int a[], int n) { int minpos; int i,j,t; for(i=0;i<n-1;i++) { minpos = i; for(j=i+1; j<n;j++) { if(a[minpos] > a[j]) minpos = j; } if(minpos != i) { t = a[i]; a[i] = a[minpos]; a[minpos] = t; } } }#include<stdio.h> #include<conio.h> #define SIZE 10 void selection_sort(int [], int); void main() { int a[SIZE],n,i; printf("Enter how many elements "); scanf("%d",&n); /*Input array */ for(i=0;i<n;i++) { printf("Enter element %d ",i+1); scanf("%d", &a[i]); } selection_sort(a,n); /*Output array */ for(i=0;i<n;i++) printf("%d ",a[i]); getch(); } void selection_sort(int a[], int n) { int minpos; int i,j,t; for(i=0;i<n-1;i++) { minpos = i; for(j=i+1; j<n;j++) { if(a[minpos] > a[j]) minpos = j; } if(minpos != i) { t = a[i]; a[i] = a[minpos]; a[minpos] = t; } } }OutputEnter how many elements 5 Enter element 1 99 Enter element 2 88 Enter element 3 77 Enter element 4 66 Enter element 5 55 55 66 77 88 99 Data Structures & Algorithms Tutorials for Beginners Data Structures Tutorials DSA Tutorials