C Program To Implement Selection Sort Algorithm To Print N Numbers In Descending 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:
7 0 3 1 8

Sorted list in descending order:
8 7 3 1 0

♣ Downloads ::

Comments

Popular posts from this blog

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

How to Hack Facebook Account

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