/* bubble sort sort_bubble.c */ #include /* Macro definition */ #define NUM 10 int main() { /**** (1) variable declaration ****/ int A[NUM] = {8,2,7,4,5,6,9,0,1,3}; int i, j, temp; /**** (2) processing contents ****/ /* display array before sorting */ printf("Array before sorting: \n"); for (i=0;i%d ", A[k]); } else { printf("%d ", A[k]); } // Insert new line if k reaches the end of the array if (k == NUM - 1) { printf("\n"); } } // If compared number is smaller than reference number, swap them if (A[j] > A[j+1]) { temp = A[j]; A[j] = A[j+1]; A[j+1] = temp; swaps++; } } printf("\n"); } /* display array after sorting */ printf("Sorted array: \n"); for (i=0;i