selection sort using function

#include<stdio.h>

int selectionsort(int n)
{
    int i , num ,j , a[1000], pos , temp , k;

    num = n;
    printf("\n Enter the elements :- \t");
    for(i =0; i<num; i++)
    {
        scanf("%d",&a[i]);
    }

    k=num-1;
    for(i=0 ; i<k; i++)
    {
        pos =i;

        for(j= i+1 ; j<num ; j++)
        {
            if(a[pos] > a[j])
            {
                pos = j;
            }
        }
        if(pos != i)
        {
            temp = a[i];
            a[i] = a[pos];
            a[pos] = temp;
        }
    }

    printf(" The Final Array After Sorting Is : \n");

    for(i=0 ; i<num; i++)
    {
        printf("\t%d",a[i]);
    }

    return 0;
}


int main()
{
    int n , x;

    printf(" Enter the number of array elements : - \t");
    scanf("%d",&n);

    x = selectionsort(n);

    return 0;
}




OUTPUT : -    




For Other Programs Visit The WebSite:-   https://www.techapurba.com/

Follow Me On Social Media :-

For tech related videos visit my other website :- https://apurbatechinfo.blogspot.com/

Post a Comment

0 Comments