C Program Selection Sort

#include<stdio.h>
#include<conio.h>
void main()
{
    clrscr();
    int size, array[50], i, j, temp;
    printf("Enter Array Size : ");
    scanf("%d",&size);
    printf("Enter Array Elements : ");
    for(i=0; i<size; i++)
    {
        scanf("%d",&array[i]);
    }
    printf("Sorting array using selection sort...\n");
    for(i=0; i<size; i++)
    {
        for(j=i+1; j<size; j++)
        {
            if(array[i]>array[j])
            {
                temp=array[i];
                array[i]=array[j];
                array[j]=temp;
            }
        }
    }
    printf("Now the Array after sorting is :\n");
    for(i=0; i<size; i++)
    {
        printf("%d  ",array[i]);
    }
    getch();
}

Run:

No comments:

Post a Comment

100 C Programs with Code and Output

Program 1: C Program To Read Two Numbers And Print The Sum Of Given Two Numbers. Program 2: C Program To Read Three Numbers And Prin...