Ask Question - Get Answer

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

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

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

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

Answer(s):

Bubble 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(i=0; i<n; i++)

    {

        for(j=n-1; j>=i+1; j--)

        {

            k=a[j-1];

            if(a[j-1]>a[j])

            {

                a[j-1]=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:52 PM

Please log in to Upvote, Downvote and Report
           

Related Q/A:

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

1 Ans Write a C program to print Pascal Triangle

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

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

1 Ans A Quest for Peace in the Middle East: Recent Perspectives - composition

1 Ans Bank Exam all important Writing Materials

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

2 Ans BPSC aptitude test all programs solutions here

1 Ans Write a C program to check a perfect number

1 Ans Best Web development site in the internet ?