Monday, 20 May 2013

Selection Sort


#include<stdio.h>
#include<conio.h>
void main()
{
int a[50];
int i,n,j,k,x,temp;
printf("Enter the number of elements you want to enter");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("a[%d] =",i);
scanf(" %d",&a[i]);
}

for(j=0;j<n-1;j++)
 {
 for(k=j+1;k<n;k++)
  {
  if(a[j]>a[k])
   {
   temp=a[j];
   a[j]=a[k];
   a[k]=temp;
   }
  }
 }
 printf("\n\nSORTED ARRAY IS:\n\n");
 for(x=0;x<n;x++)
 {
 printf("\na[%d] = %d",x,a[x]);
 }
getch();
}

No comments:

Post a Comment

full details in json
Proudly Powered by Blogger.
back to top