# include int main ( ) { // // If we know the values of an array, we can initialize the array // like this: // int a[10] = { 210, 421, 132, 343, 854, 165, 276, 587, 398, 109 }; int i; int j; int t; // // Step 1: Print the original array. // printf ( "\n" ); printf ( "Initial array:\n" ); printf ( "\n" ); for ( i = 0; i < 10; i++ ) { printf ( "a[%i] = %i\n", i, a[i] ); } // // Step 2: Sort the array. // printf ( "\n" ); printf ( "Sorting:\n" ); printf ( "\n" ); for ( i = 1; i < 10; i++ ) { printf ( "Deal with the value %i, currently stored in a[%i]\n", a[i], i ); for ( j = i; 0 < j; j-- ) { if ( a[j-1] < a[j] ) { printf ( " %d is NOT smaller than %d, stop at position %i\n", a[j], a[j-1], j ); break; } printf ( " %d is smaller than %d, move to position %i\n", a[j], a[j-1], j-1 ); t = a[j]; a[j] = a[j-1]; a[j-1] = t; } } // // Step 3: Print the sorted array. // printf ( "\n" ); printf ( "Sorted array:\n" ); printf ( "\n" ); for ( i = 0; i < 10; i++ ) { printf ( "a[%i] = %i\n", i, a[i] ); } return 0; }