Develop a ‘C’ program to create and implement BUBBLE SORTING.

 

DATA STRUCTURE & ALGORITHM USING C – LAB (2018407)

UNIT – 12

Develop a ‘C’ program to create and implement BUBBLE SORTING.

 

#include<stdio.h>
main()
{
    int a[10],i,j,temp,n;
    printf("\n Enter the max no.of Elements to Sort: \n");
    scanf("%d",&n);
    printf("\n Enter the Elements : \n");
    for(i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=0; i<n; i++)
        for(j=i+1; j<n; j++)
        {
            if(a[i]>a[j])
   {
                temp=a[i];
                a[i]=a[j];
                a[j]=temp;
            }
        }
    for(i=0; i<n; i++)
    {
        printf("%d\t",a[i]);
    }
    getch();
}
Output:
Enter the max no. of Elements to Sort:
5
Enter the Elements:
45
21
89
78
99
21      45      78      89      99

Post a Comment

0 Comments