Fri Jun 15 2018
Bubble Sort
C Programming3152 views
File Name: bubble-sort.c
#include<stdio.h>
int main() {
int data[10], i, j, temp;
printf("Enter 10 random number to sort in ascending order:\n");
for(i = 0; i < 10; i++)
scanf("%d", &data[i]);
/* Sorting process start */
for(i = 0; i < 10; i++) {
for(j = i+1; j < 10; j++) {
if(data[j] < data[i]) {
temp = data[i];
data[i] = data[j];
data[j] = temp;
}
}
}
printf("After sort\n");
for(i = 0; i < 10; i++)
printf("%d\n",data[i]);
return 0;
}
/* Output */
Enter 10 random number to sort in ascending order:
4
6
1
8
3
7
2
5
9
0
After sort
0
1
2
3
4
5
6
7
8
9
Reference:
Author:Geekboots