Ask Question - Get Answer

2 Ans Write a C program to implement Selection sort data structure and algorithm

Asked by AL MaMun (4 Golds) Friday, 31 Jul 2020, 04:44 PM at (Education Tutorials)

Please log in to answer, like and save
0
Save 0

<<< Previous
Log in to Answer Next >>>

Answer(s):

#include<bits/stdc++.h>

int action(int A[], int n)

{

    int i, j, index_min, temp;

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

    {

        index_min = i;

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

        {

            if(A[j] < A[index_min])

            {

                index_min = j;

            }

        }

        if(index_min != i)

        {

            temp = A[i];

            A[i] = A[index_min];

            A[index_min] = temp;

        }

    }

}

int main()

{

    int a[10] = {11, 3, 52, 9, 112};

    action(a, 5);

    for(int i=0; i<5; i++)

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

    return 0;

}


Answered by Birds of the sky (2 Golds) Saturday, 25 Dec 2021, 11:48 AM

Please log in to Upvote, Downvote and Report

C Program of Selection sort data structure and algorithm :


#include<stdio.h>

int main()

{

    int i, j, n, arr[100], min, temp;

    scanf("%d", &n);

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

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

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

    {

        min=i;

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

        {

            if(arr[j]<arr[min])

                min=j;

        }

        temp=arr[i];

        arr[i]=arr[min];

        arr[min]=temp;

    }

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

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

    return 0;

}


Answered by AL MaMun (4 Golds) Friday, 31 Jul 2020, 04:45 PM

Please log in to Upvote, Downvote and Report
           

Related Q/A:

1 Ans Write a C program to implement Insertion sort data structure and algorithm

1 Ans A C Program to split a number into digits

1 Ans Which is the best and easy C programming learning website ?

1 Ans Write a C program to check Bubble sort data structure and algorithm

2 Ans Write a C program to implement Selection sort data structure and algorithm

1 Ans Write a C Program to find factorial using recursion

1 Ans How to Learn HTML - HyperText Markup Language easily? 

1 Ans Write a C program to check a Prime number

1 Ans Write a C Program to check Anagrams of two strings

1 Ans Best Web development site in the internet ?