Program to sort the numbers using selection sort

Here is the program to sort the given integer in ascending order using selection sort method. Please find the link to the pictorial tutor of the sorting. This program needs to enter the length of the entering array, followed by the array to be sorted. The entered integers are stored in the array A.

Logic : Here, to sort the data in ascending order, the first element A[0] is compared with all the other elements till the end of the array. If it is greater than any other the elements then they are interchanged. So after the first iteration of the outer for loop smallest element will be placed at the first position. The same procedure is repeated for the other elements too.

If we complement the if condition in this program, it will give out the sorted array in descending order. Sorting can also be done in other methods, like bubble sorting and insertion sorting, which follows in the next pages.

#include <stdio.h>
        int A[20], N, Temp, i, j;
        printf("\n\n\t ENTER THE NUMBER OF TERMS...: ");
        printf("\n\t ENTER THE ELEMENTS OF THE ARRAY...:");
        for(i=1; i<=N; i++)
                scanf("\n\t\t%d", &A[i]);
        for(i=1; i<=N-1; i++)
                for(j=i+1; j<=N;j++)
                                Temp = A[i];
                                A[i] = A[j];
                                A[j] = Temp;
        printf("\n\tTHE ASCENDING ORDER LIST IS...:\n");
        for(i=1; i<=N; i++)

Download exe and source code here.

Editorial Team
Editorial Team

We are a group of young techies trying to provide the best study material for all Electronic and Computer science students. We are publishing Microcontroller projects, Basic Electronics, Digital Electronics, Computer projects and also c/c++, java programs.

15 thoughts on “Program to sort the numbers using selection sort

  1. I want a C++ program that is done by using class.
    the program contains the following:
    1.done by sorting algorithms(selection sorting,bubble sorting or
    insertion sorting one of this is enough).
    2.the program contains students grade,GPA,age,id,name,mark,credithour,course,department etc forfive students .
    3.the program can sort using GPA and name.
    4.please send it if possible today else tomorrow.

    GOOD BY!

  2. bubble or insertion or insertion sorting and searching student atributes or data( name ,id, age ,gpa and in one c++ program in classdefinition

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the latest updates on your inbox

Be the first to receive the latest updates from Codesdoc by signing up to our email subscription.