Skip to content

Instantly share code, notes, and snippets.

@devils-ey3
Created September 21, 2016 11:06
Show Gist options
  • Save devils-ey3/0924feb1d830c4b6607ac1d89baede97 to your computer and use it in GitHub Desktop.
Save devils-ey3/0924feb1d830c4b6607ac1d89baede97 to your computer and use it in GitHub Desktop.
Selection sort by C
#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