-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBubble Sort.c
36 lines (34 loc) · 873 Bytes
/
Bubble Sort.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <stdio.h>
//declaring Standard input output header file
#include <stdlib.h>
//declaring library header file
int main()
//main function
{
int n;
printf("Size of the Array : ");
scanf("%d",&n);
int arr[100]={220, 146, 22, 19, 6, 42, 14, 5, 48, 47, 17, 39, 51, 7, 2, 99, 65, 7};
//declaring integer type Array
for(int i=0;i<n-1;i++){
//declaring inner for loop
for(int j=0;j<n-2;j++){
//declaring nested for loop
if(arr[j]>arr[j+1]){
//condition
//swapping values
int x;
x=arr[j];
arr[j]=arr[j+1];
arr[j+1]=x;
}
}
}
printf("Bubble Sorted Array : ");
for(int i=0;i<7;i++){
printf("%d\t",arr[i]);
//print values
}
printf("\n");
return 0;
}