Bubble sort program in C || Arrays || C programming
In this, we are going to see a program in which we are going to sort the array in the ascending order using bubble sort method in C Programming Language.

//Sorts the array in the ascending order using bubble sort method.

#include <stdio.h>
void main()
{
    int i, j, temp;
    int x[50], n;
    printf("Enter how many numbers you want to sort out of 50: ");
    scanf("%d", &n);
    printf("Enter %d numbers to sort in asccending order:\n", n);
    for (i = 0; i < n; i++)
    {
        scanf("%d", &x[i]);
    }

    for (i = 0; i < n; i++)
    {
        for (j = 0; j < n; j++)
        {
            if (x[j] > x[j + 1])
            {
                temp = x[j];
                x[j] = x[j + 1];
                x[j + 1] = temp;
            }
        }
    }

    printf("The sorted array is....\n");
    for (i = 0; i < n; i++)
    {
        printf("\t%d", x[i]);
    }
}

#ENJOY CODING


Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post