Selection Sort
Here, you will learn the source code of Selection Sort in C programming language. Selection Sort is a sorting algorithm, It is used to sort array elements in any order(ascending or descending).
Selection Sort in C example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | //c program to perform selection sort #include <stdio.h> int main() { int i, j, num, min, temp; printf("Input number of elements in array : "); scanf("%d", &num); int array[num]; printf("Input %d values ",num); for(i = 0; i < num; i++) { scanf("%d", &array[i]); } for(i=0; i<num; i++) { for(j=i+1; j<num; j++) { if(array[i] > array[j]) { temp=array[i]; array[i]=array[j]; array[j]=temp; } } } printf("\n\nSorted array: "); for(i = 0; i < num; i++) { printf("%d ", array[i]); } return 0; } |
Output
Read Also
Check out our DAA Lab Manual and Programs