# Write a program to sort data using a selection sort algorithm – IGNOU BCA Assignment 2015 – 16

By | October 6, 2015

BACHELOR OF COMPUTER APPLICATIONS

Course Code : BCSL-045
Course Title : Introduction to Algorithm Design Lab
Assignment Number : BCA(IV)/L-045/Assignment/2015
Maximum Marks : 50
Weightage : 25%

## Write a program to sort data using a selection sort algorithm.

#include<stdio.h>
void main()
{
int MIN,MIN_POS,I,J,TEMP,List[]={6,3,0,4,8,2,5,9,1,7};
int N=10;
clrscr();
printf(“\n****SELECTION SORT****\n”);
printf(“\n\nList Before Sorting :\n\n”);
for(J=0;J<N;J++)
{
printf(“%d “,List[J]);
}
for(I=0;I<N;I++)
{
MIN=List[I];
MIN_POS=I;
for(J=I;J<N;J++)
{
if(List[MIN_POS]>List[J])
{
MIN_POS=J;
MIN=List[J];
}
}
List[MIN_POS]=List[I];
List[I]=MIN;
}
printf(“\n\nList Before Sorting :\n\n”);
for(J=0;J<N;J++)
{
printf(“%d “,List[J]);
}
getch();
}

Code:

#include<stdio.h>
void main()
{
int MIN,MIN_POS,I,J,TEMP,List[]={6,3,0,4,8,2,5,9,1,7};
int N=10;
clrscr();
printf(“\n****SELECTION SORT****\n”);
printf(“\n\nList Before Sorting :\n\n”);
for(J=0;J<N;J++)
{
printf(“%d “,List[J]);
}
for(I=0;I<N;I++)
{
MIN=List[I];
MIN_POS=I;
for(J=I;J<N;J++)
{
if(List[MIN_POS]>List[J])
{
MIN_POS=J;
MIN=List[J];
}
}
List[MIN_POS]=List[I];
List[I]=MIN;
}
printf(“\n\nList Before Sorting :\n\n”);
for(J=0;J<N;J++)
{
printf(“%d “,List[J]);
}
getch();
}

ScreenShots: