Ask Question - Get Answer

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

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

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

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

Answer(s):

Insertion sort C program :


#include<stdio.h>

int main()

{

    int a[100], i, j, k, n;

    scanf("%d", &n);

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

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

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

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

    printf("\n\n");


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

    {

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

        {

            k = a[i];

            if(a[i]>a[j])

            {

                a[i]=a[j];

                a[j]=k;

            }

        }

    }

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

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

}


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

Please log in to Upvote, Downvote and Report
           

Related Q/A:

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

1 Ans Write a C Program to find factorial using recursion

1 Ans A C Program to split a number into digits

1 Ans Best Web development site in the internet ?

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

1 Ans Write a C program to check a Palindrome Number

2 Ans Write a C program for Binary Search algorithm

1 Ans The general rules for constructing names for variables (unique identifiers)

2 Ans BPSC Programming Aptitude Lab Test Important programs

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