#include <stdio.h>
void bubbleSort(int array[], int n) {
int i, j;
for (i = 0; i < n-1; i++) {
// Last i elements are already in place
for (j = 0; j < n-i-1; j++) {
if (array[j] > array[j+1]) {
// Swap array[j] and array[j+1]
int temp = array[j];
array[j] = array[j+1];
array[j+1] = temp;
}
}
}
}
void printArray(int array[], int size) {
for (int i = 0; i < size; i++) {
printf("%d ", array[i]);
}
printf("\n");
}
int main() {
int array[] = {64, 34, 25, 12, 22, 11, 90};
int n = sizeof(array) / sizeof(array[0]);
printf("Unsorted array: \n");
printArray(array, n);
bubbleSort(array, n);
printf("Sorted array: \n");
printArray(array, n);
return 0;
}
When you run this program, it will output the unsorted array first, then apply the bubble sort algorithm, and finally print the sorted array. Bubble sort has a time complexity of (O(n^2)) in the worst and average cases, making it inefficient for large datasets. However, it is simple and can be useful for small sets of data or educational purposes.