Like us on Facebook and stand a chance to win pen drives!

Selection Sort Algorithm




#include<stdio.h>
int main()
{
  int array[11];
   int i;
    for(i=1;i<11;i++)
     {
        printf("Enter N0 :",i);
        scanf("%d", &array[i]);
     }
int n=11;
int j;
for (j=1;j<11;j++)
{
 int smallest= j;
 int i=0;
 for (i=j+1;i<11;i++)
 {
  if (array[i]<array[smallest])
  {
  smallest = i;
   int temp=array[j];
  array[j]=array[smallest];
         array[smallest]=temp;
  smallest=j;
  }
 }
}

  int m;
  for(m=1;m<11;m++)
   {
      printf("array[%d]=%d\n",m,array[m]);
}
}






Comment with Facebook


Copyright © 2012 SLIIT Helper.