Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions bubblesort
Original file line number Diff line number Diff line change
@@ -0,0 +1,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;
}