Selection Sort in C

C Program to Implement Selection Sort. This Algorithm is very simple. Find the smallest element in the array and swap it. That's all you will get a sorted array at the end.

Source code :



#include <stdio.h>

int main(){

int array[] = {1,45,10,35,100,13,147,500,80};
int size = sizeof(array)/sizeof(array[0]);

int i,j,min;

for (i = 0; i < size ; i++){
    
    
    for(j = i+1  ; j < size ; j++){
        
        if(array[j] < array[i]){
            
            min = array[j];
            array[j] = array[i];
            array[i] = min;
            
        }
    }
    
    
}


for(i = 0 ; i < size ; i++){
    printf("%d
",array[i]);
}


return 0;

}

Output :

1
10
13
35
45
80
100
147
500

Output :


                

Comments :