Selection shorting in c Programming

20 Sep 2022 Balmiki Mandal 0 C Programming

How to Implement Selection Sort in C Programming

Selection sort is a simple sorting algorithm that works by repeatedly finding the minimum element from the unsorted part of the array and putting it at the beginning of the sorted part of the array.

How you can implement selection sort in C programming:

Selection shorting in c Programming

#include<stdio.h>
void main()
{
    int a[5],i,j,t,ele;
    ele=sizeof(a)/sizeof(a[0]);
    printf("Enter the array elements:");
    for(i=0;i<ele;i++)
    scanf("%d",&a[i]);
    printf("Unshorted Elements:");
    for(i=0;i<ele;i++)
    printf(" %d",a[i]);
    printf("\n");
    for(i=0;i<ele;i++)
    {
        for(j=i+1;j<ele;j++)
        {
            if(a[i]>a[j])
            {
                t=a[i];
                a[i]=a[j];
                a[j]=t;
            }
        }
    }
    printf("shorted Elements:");
    for(i=0;i<ele;i++)
    printf(" %d",a[i]);
    printf("\n");
}

Output:

Enter the array elements: 5 15 1 25 12
Unsorted Elements:  5 15 1 25 12
shorted Elements:  1 5 12 15 25

Further Reading:

Bubble shorting in c programming

Bubble short in string in c

Write a c program to short 2D array using bubble short

Selection shorting in c Programming

Enroll Now:

C-Programming From Scratch to Advanced 2023-2024] "Start Supercharging Your Productivity!"

Contact Us:

  • For any inquiries, please email us at [[email protected]].
  • Follow us on insta  [ electro4u_offical_ ] for updates and tips.

 

Note: If you encounter any issues or specific errors when running this program, please let me know and I'll be happy to help debug them!

BY: Balmiki Mandal

Related Blogs

Post Comments.

Login to Post a Comment

No comments yet, Be the first to comment.