The first step is add braces to the code, in all the optional places where you left them out.
So
Code:
for (i = 0; i < 8; ++i) {
for (j = i + 1; j < 8; j++) {
if (a[i] > a[j]) {
swap(&a[i], &a[j]);
}
}
}
for (i = 0; i < 8; ++i) {
printf("after pass 1: %d\n", a[i]);
}
Second, if you want to print out something for each pass, then move the printing stuff inside the outer loop, but after the inner loop, say
Code:
for (i = 0; i < 8; ++i) {
for (j = i + 1; j < 8; j++) {
if (a[i] > a[j]) {
swap(&a[i], &a[j]);
}
}
for (k = 0; k < 8; ++k) {
printf("after pass %d: %d\n", i, a[k]);
}
}
By always using braces, it makes it much easier to move code around, and be sure that it is going to still have the same effect that you expect.
You can then refine that to print the "after pass" only once, and all the numbers on the same line, say
Code:
for (i = 0; i < 8; ++i) {
for (j = i + 1; j < 8; j++) {
if (a[i] > a[j]) {
swap(&a[i], &a[j]);
}
}
printf( "after pass %d:", i );
for (k = 0; k < 8; ++k) {
printf(" %d", a[k]);
}
printf( "\n" );
}