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 How to Learn HTML - HyperText Markup Language easily? 

1 Ans A C program to input and display an Array

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

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

1 Ans Bank Exam all important Writing Materials

1 Ans Write a C program to print Pascal Triangle

3 Ans BPSC Assistant Programmer Lab Aptitude test Programs and Queries with Proper solution (Taken By BCC)

1 Ans Write a C program to print Fibonacci number using recursion

1 Ans Write a C program to check a perfect number

1 Ans Write a C program for Interest Calculation