Solved programming problem

How to Sort an Array Using Bubble Sort Method in C.

Source code

#include <stdio.h>

int main()

{

    int i,j,n,array[100],swap;

    printf("Please Enter Array Size: ");

    scanf("%d",&n);

    printf("Please Enter Array Element: ");

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

    {

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

    }

    ///swapping part

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

    {

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

        {

            if(array[j]>array[j+1])

            {

                swap = array[j];

                array[j] = array[j+1];

                array[j+1] = swap;

            }

        }

    }

    printf("Your Sorted Array: ");

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

    {

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

    }printf("");

    return 0;

}

Output

Please Enter Array Size: 5


Please Enter Array Element: 4 1 0 9 2


Your Sorted Array: 0 1 2 4 9

Join the discussion

Add your comment