Created
September 21, 2016 11:06
-
-
Save devils-ey3/0924feb1d830c4b6607ac1d89baede97 to your computer and use it in GitHub Desktop.
Selection sort by C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() | |
{ | |
int size,array[100],i,j,temp=0; | |
printf("Enter the index number: "); | |
scanf("%d",&size); | |
printf("\ninsert the numbers into the array: "); | |
for(i=0; i<size; i++) | |
{ | |
scanf("%d",&array[i]); | |
} | |
int min; | |
for (i=0;i<size-1;i++) | |
{ | |
min = i; | |
for (j=i+1;j<size;j++) | |
{ | |
if (array[j]<array[min]) | |
{ | |
min = j; | |
} | |
} | |
if (!(min==i)) | |
{ | |
temp = array[i]; | |
array[i]=array[min]; | |
array[min]=temp; | |
} | |
} | |
printf("\nthe sorted numbers are: "); | |
for(i=0; i<size; i++) | |
{ | |
printf("%d ",array[i]); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment