Selection Sorting Method – C Program
write a c program to accept array from user and sorting all element using Selection sort method.
#include<stdio.h>
#include<conio.h>
void main()
{
int arr[10],i,j,k,temp, no;
printf("Enter size of array =\n");
scanf("%d",&no);
printf("\nPlease enter Elements of Array =\n");
for(i=0; i<no; i++)
{
scanf("%d",&arr[i]);
}
for(i=0; i<no; i++)
{
k=i;
for(j=i; j<no; j++)
{
if(arr[k]>arr[j])
k=j;
}
if(k!=i)
{
temp=arr[k];
arr[k]=arr[i];
arr[i]=temp;
}
}
printf("The Sorted Array is = \n");
for(i=0;i<no;i++)
{
printf("%d\t",arr[i]);
}
getch();
}
The output of Selection sort c program is :
Enter size of array =
7
Please enter Elements of Array =
8
25
84
23
56
9
36
The Sorted Array is =
8 9 23 25 36 56 84