C program for selection sort

source code:


#include<stdio.h>
int main()
{
 int s,i,j,temp,a[20];
  printf("Enter total elements: ");
  scanf("%d",&s);
 printf("Enter %d elements: ",s);
  for(i=0;i<s;i++)
 scanf("%d",&a[i]);
 for(i=0;i<s;i++)
{
      for(j=i+1;j<s;j++)
{
           if(a[i]>a[j])
{
               temp=a[i];
              a[i]=a[j];
              a[j]=temp;
           }
      }
  }

  printf("After sorting is: ");
  for(i=0;i<s;i++)
      printf(" %d",a[i]);
  getch();
  return 0;
}

Comments

Popular posts from this blog

8086 STRING MANIPULATION –FIND AND REPLACE A WORD

Animated Circles In C++

C program to find out the sum of series 1 + 2 + …. + n.