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 Which is the best and easy C programming learning website ?

1 Ans Write a C program to find the highest and lowest number in a series

2 Ans BPSC Programming Aptitude Lab Test Important programs

1 Ans Write a C program to implement x power n using recursion

1 Ans Write a C program to print Fibonacci number series

1 Ans Write a C program for Interest Calculation

1 Ans Single Digit Interest Rate in the Banking Sector: Problems and Prospects - essay writing

1 Ans Bank Exam all important Writing Materials

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

1 Ans Write a C++ program for BigMod math