[ create a new paste ] login | about

Link: http://codepad.org/eGH0SeJp    [ raw code | output | fork ]

C, pasted on Jul 12:
#include <stdio.h>
#define size 5

int main(){
    int arr[5]={5,1,8,6,4};
    int least, tmp;
    int i,j;

    for(i=0;i<size;i++){
      least=i;
     for(j=i+1;j<size-i-1;j++){
        if(arr[j]<arr[least])     
           least=j;
     }
   tmp = arr[i]; 
   arr[i]=arr[least]; 
   arr[least]=tmp;
}
        for(i=0;i<size;i++)
           printf("%d ",arr[i]);

return 0;
}


Output:
1
1 5 8 6 4 


Create a new paste based on this one


Comments: