BUBBLE SORT

C Program – BUBBLE SORT Program Implementation.


#include<stdio.h>

int main()

{

int count,temp,i,j,arr[20];

printf("How many numbers of elements do you want to enter:? ");

scanf("%d",&count);

printf("Enter %d elements: ",count);

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

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

//Bubble sorting algorithm

for(i=count-2;i>=0;i--){

for(j=0;j<=i;j++){

if(arr[j]>arr[j+1]){

temp=arr[j];

arr[j]=arr[j+1];

arr[j+1]=temp;

}

}

}

printf("After sorting the elements are: ");

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

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

return0;

}
OUTPUT:-

Leave a Reply

Your email address will not be published. Required fields are marked *