Selection Sort

From Ta Wiki
Revision as of 23:59, 7 March 2019 by Tata (talk | contribs) (Created page with "<pre> #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); f...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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;
}