Solved programming problem

How to Sort an Array Using Selection Method(1) in C.

Source code

#include <stdio.h>

int main()

{

    int array[100],n,i,j;

    int index,temp;

    printf("Please Enter The Array Size: ");

    scanf("%d",&n);

    printf("Please Enter Array Element: ");

    for(i=0; i<n; i++)

    {

        scanf("%d",&array[i]);

    }

    ///selection sorting

    for(i=0; i<n; i++)

    {

        index = i;

        for(j=i+1; j<n; j++)

        {

            if(array[j]<array[index])

            {

                index=j;

            }

        }

        if(index!=i)

        {

            temp = array[index];

            array[index] = array[i];

            array[i]= temp;

        }

    }

    printf("Your Sorted Array: ");

    for(i=0; i<n; i++)

    {

        printf("%d ",array[i]);

    }

 

    return 0;

}

Output

Please Enter The Array Size: 5


Please Enter Array Element: 1 65 2 8 9


Your Sorted Array:


1 2 8 9 65

Join the discussion

Add your comment