C Program To Implement Selection Sort Algorithm To Print N Numbers In Ascending Order


♣ Try it Out ::
#include<stdio.h>
#include<conio.h>

void SelectionSort(int*, int);

int main()
{
    int ArraySize;

    printf("How many numbers you wish to enter: ");
    scanf("%d", &ArraySize);

    int Array[ArraySize], i;

    printf("Enter %d integers: \n", ArraySize);
    for(i=0; i<ArraySize; i++)
        scanf("%d", &Array[i]);

    SelectionSort(Array, ArraySize);

    printf("\nSorted list in ascending order:\n");
    for(i=0; i<ArraySize; i++)
        printf("%d ", Array[i]);

    getch();
    return(0);
}

void SelectionSort(int Arr[], int Size)
{
    int Swap, i, j;

    for(i=0; i<Size-1; i++)
        for(j=i+1; j<=Size-1; j++)
            if(Arr[i] > Arr[j])
            {
                Swap   = Arr[i];
                Arr[i] = Arr[j];
                Arr[j] = Swap;
            }
}

♣ Output ::
How many numbers you wish to enter: 5
Enter 5 integers:
4 0 2 7 1

Sorted list in ascending order:
0 1 2 4 7

♣ Downloads ::

Comments

Popular posts from this blog

C++ :: Topological Sort Algorithm (using DFS)

How to Hack Facebook Account

C++ :: Strongly Connected Components Algorithm (SCC)