C Program Code for Selection Sort


Algorithm:-

1.Start
2.Accept the size of array and then elements.
3.Check whether (i<n-1) 
   if yes goto 4
   else goto 13
4.min=i
5.j=i+1
6.Check whether j<n
   if yes goto step 7
   else goto step 8
7.Check whether a[min]>a[j]
   if yes min=j
8.Increment j by 1,return to 6
9.Check whether (min|=j)
   if yes interchange a[i] and a[min]
10.Increment i by 1
11.Return to step 3
12.Display sorted array.
13.Stop

Program:-

/*Program to perform selection Sort - Crazy Factzz */
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a[100],i,k,j,n;
printf("\n Enter the size of array : ");
scanf("%d",&n);
printf("Enter the elements \n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n-1;i++)
{
int min=i;
for (j=i+1;j<n;j++)
{
if (a[i]>a[j])
min=j;
if(min|=i)
{
int t=a[i];
a[i]=a[min];
a[min]=t;
}
}
}
printf("\n The Sorted array is \n");
for(i=0;i<n;i++)
printf("%d \n",a[i]);
getch();
}

For more C programs - click here

Popular posts from this blog

8051 Assembly Program Code for Sorting in Descending Order - Keil - AT89C51

Mini Militia Chat Codes - Shortforms