Selection Sort
Jump to navigation
Jump to search
#include<stdio.h> int main(){ int arr[10000],n,i,j,min,temp; printf("Enter number of numbers : "); scanf("%d",&n); printf("Enter %d numbers : ",n); for(i=0;i<n;i++){ scanf("%d",&arr[i]); } //---------- SORT ----------- for(i=0;i<n;i++){ min=i; for(j=i;j<n;j++){ if(arr[j]<arr[min]) min=j; } temp=arr[i]; arr[i]=arr[min]; arr[min]=temp; } //--------------------------- printf("Sorted List : "); for(i=0;i<n;i++){ printf("%d ",arr[i]); } scanf(" "); return 0; }