We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 7a67996 commit 1deaf6aCopy full SHA for 1deaf6a
sort/bubble_sort/c/bubblesorting.c
@@ -0,0 +1,38 @@
1
+#include<stdio.h>
2
+void BubbleSort(int n, int a[]){
3
+ int temp,count=0;
4
+ for (int i = 0; i < n-1; i++)
5
+ {
6
+ for (int j = 0; j < n-i-1; j++)
7
8
+ if(a[j]>a[j+1]){
9
+ temp=a[j];
10
+ a[j]=a[j+1];
11
+ a[j+1]=temp;
12
+ count++;
13
+ }
14
15
+ if(count==0){
16
+ break;
17
18
19
+ printf("The sorted array is:\n");
20
+ for (int k = 0; k <n ; k++)
21
22
+ printf("%d ",a[k]);
23
24
+
25
+}
26
+int main(){
27
+ int a[99],n;
28
+ printf("Enter the size of the array:\n");
29
+ scanf("%d",&n);
30
+ printf("Enter the elements of the array:\n");
31
+ for (int i = 0; i < n; i++)
32
33
+ scanf("%d",&a[i]);
34
35
+ BubbleSort(n,a);
36
37
+return 0;
38
0 commit comments