Program
Time Complexity: O(n2)
#include <stdio.h>
int main()
{
printf("***************************************************************");
printf("\n***************************************************************");
printf("\n** WAP to sort the elements of an array using bubble sort **");
printf("\n** Created by Sheetal Garg **");
printf("\n** Assistant Professor **");
printf("\n** Phone No:9467863365 **");
printf("\n***************************************************************");
printf("\n***************************************************************\n");
int a[10],n,i,j,temp;
printf("enter the no. of elements in array");
scanf("%d",&n);
printf("enter array elements");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n-1;i++)
for(j=0;j<n-1-i;j++)
if(a[j]>a[j+1])
{
temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
printf("array after sorting is \n");
for(i=0;i<n;i++)
printf("%d \t",a[i]);
return 0;
}
Output
***************************************************************** ***************************************************************** ** WAP to sort the elements of an array using bubble sort ** ** Created by Sheetal Garg ** ** Assistant Professor ** ** Phone No:9467863365 ** ***************************************************************** ***************************************************************** enter the no. of elements in array 5 enter array elements 23 32 24 54 15 array after sorting is 15 23 24 32 54