Selection Sort in C Programming language4 months ago

#include <stdio.h>

int main()
{
  int N;
  scanf("%d",&N);
  int arr[N];
  for(int index=0; index < N; index++){
    scanf("%d",&arr[index]);
  }

  for(int index=0; index < N; index++){
    int smallestValueIndex = index;
    for(int compareIndex = index+1; compareIndex < N; compareIndex++){
        if(arr[compareIndex] < arr[smallestValueIndex]){
            smallestValueIndex = compareIndex;
        }
    }
    int temp = arr[smallestValueIndex];
    arr[smallestValueIndex] = arr[index];
    arr[index] = temp;
  }

  for(int index=0; index < N; index++){
    printf("%d ",arr[index]);
  }

}