#include<stdio.h>intmain(){voidBubbleSort(inta[],intn){for(inti=0;i<(n-1);i++){for(intj=0;j<n-i-1;j++){if(a[j]>a[j+1]){a[j]=a[j]+a[j+1];a[j+1]=a[j]-a[j+1];a[j]=a[j]-a[j+1];}}}}intn,i;printf("———————————————————————————————————————————");printf("\nImplementation of a Bubble Sort\n");printf("———————————————————————————————————————————");printf("\nEnter the number of elements ");scanf("%d",&n);inta[n];for(i=0;i<n;i++){scanf("%d",&a[i]);}BubbleSort(a,n);printf("\nSorted element(s): ");for(i=0;i<n;i++){printf("%d ",a[i]);}printf("\n———————————————————————————————————————————\n");return0;}
Output
kodingwindow@kw:~$ gcc kw.c kodingwindow@kw:~$ ./a.out
———————————————————————————————————————————
Implementation of a Bubble Sort
———————————————————————————————————————————
Enter the number of elements 6
12
23
-104
-1
0
90
Sorted element(s): -104 -1 0 12 23 90
———————————————————————————————————————————
kodingwindow@kw:~$
Dear User, Thank you for visitng KodingWindow. If you are interested in technical articles, latest technologies, and our journey further, please follow us on LinkedIn.