#include #include // Sort an array using Bubble Sort void printArray(int a[], int n) { int i; printf("\nIndex i: "); for(i=0; i< n; i++) printf("%2d, ", i); printf("\nElement a[i]: "); for(i=0; i< n; i++) printf("%2d, ", a[i]); printf("\n\n"); } #define N 6 int main() { int a[N]= { 23, 78, 45, 8, 32, 56}; int i, j; int DEBUG= 1; // 0; printArray(a, N); // Print the unsorted array // Sort the array using Bubble Sort // Last elements in the array are sorted first for(i=0; i < N; i++) { for(j=0; j< N-1-i; j++) if (a[j+1] < a[j]) /* compare the two neighbors */ { int tmp = a[j]; /* swap a[j] and a[j+1] */ a[j] = a[j+1]; a[j+1] = tmp; } } printArray(a, N); // Print the sorted array system("pause"); }