forked from seeditsolution/pythonprogram
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbubblesort
More file actions
35 lines (27 loc) · 683 Bytes
/
Copy pathbubblesort
File metadata and controls
35 lines (27 loc) · 683 Bytes
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
/* Implementing Bubble sort in a C Program
* Written by: Chaitanya.
*/
#include<stdio.h>
int main(){
int count, temp, i, j, number[30];
printf("How many numbers are u going to enter?: ");
scanf("%d",&count);
printf("Enter %d numbers: ",count);
for(i=0;i<count;i++)
scanf("%d",&number[i]);
/* This is the main logic of bubble sort algorithm
*/
for(i=count-2;i>=0;i--){
for(j=0;j<=i;j++){
if(number[j]>number[j+1]){
temp=number[j];
number[j]=number[j+1];
number[j+1]=temp;
}
}
}
printf("Sorted elements: ");
for(i=0;i<count;i++)
printf(" %d",number[i]);
return 0;
}