Skip to content

Instantly share code, notes, and snippets.

@78526Nasir
Created February 17, 2016 13:27
Show Gist options
  • Save 78526Nasir/bd09e7265cee16bae774 to your computer and use it in GitHub Desktop.
Save 78526Nasir/bd09e7265cee16bae774 to your computer and use it in GitHub Desktop.
Selection Sort Implementation in C using Array !
/// Selection Sort ///
#include<stdio.h>
main()
{
int a[100],i,j,minIndex,temp,n;
printf("Enter How many elements on your Array :");
scanf("%d",&n);
printf("\nEnter %d values :",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("\nSelection Sort");
for(i=0;i<n-1;i++)
{
minIndex=i;
for(j=i+1;j<n;j++)
{
if(a[minIndex]>a[j])
{
minIndex=j;
}
}
temp=a[minIndex];
a[minIndex]=a[i];
a[i]=temp;
}
printf("\n\n");
for(i=0;i<n;i++)
printf("%d ",a[i]);
printf("\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment