C program to Implement Selection Sort .

Selection Sort is a simple sorting algorithm that repeatedly selects the smallest (or largest, depending on the order) element from the unsorted part of the array and swaps it with the element at the beginning of the unsorted part. The algorithm divides the array into a sorted and an unsorted region. In each iteration, the smallest element from the unsorted region is selected and moved to the sorted region.

Here’s a simple implementation of Selection Sort in the C programming language

Program :

#include<stdio.h>
main()
{
int a[20],n,temp,i,j;
printf(“Enter the Number to terms : “);
scanf(“%d”,&n);
printf(“\nEnter the Elements of the Array : “);
for(i=1;i<=n;i++)
{
scanf(“%d”,&a[i]);
}
for(i=1;i<=n-1;i++)
for(j=i+1;j<=n;j++)
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
printf(“The Ascending Order list is : “);
for(i=1;i<=n;i++)
printf(“\n%d”,a[i]);
}

Output :

Leave a Comment

Your email address will not be published.

Shopping Basket
Verified by MonsterInsights