Bubble sort in C



#include<stdio.h>

int bubblesort(int n)
{
    int i , j , num , a[1000], temp , k;

    num = n ;
    printf(" \n Enter the array elements : - \t");
    for(i=0; i<num ; i++)
    {
        scanf("%d",&a[i]);
    }

    k = num-1;

    for(i =0; i<k ; i++)
    {
        for(j=0; j<num-i-1 ; j++)
        {
            if(a[j]> a[j+1])
            {
                temp = a[j];
                a[j] = a[j+1];
                a[j+1] = temp;
            }
        }
    }

    printf(" \n\nThe Final Result after sorting is : - \t");
    for(i=0;i<num ; i++)
    {
        printf("%d\t",a[i]);
    }

    return 0;
}


int main()
{
    int n , x ;

    printf(" Enter the number of elements : \t ");
    scanf("%d",&n);

    x=bubblesort(n);

    return 0;
}


OUTPUT : - 







For Other Programs Visit The WebSite:-   https://www.techapurba.com/

Follow Me On Social Media :-





For tech related videos visit my other website :- https://apurbatechinfo.blogspot.com/

Post a Comment

0 Comments