#include <stdio.h>

int cmp(int x, int y)    // compare x and y
{
    return x > y;   // 1 if x > y, 0 otherwise
}

void swap(int *x, int *y)
{
    int tmp = *x;

    *x = *y;
    *y = tmp;
}

int main(void)
{
    int a[] = {3, 1, 4, 1, 5, 9, 2, 6, 5};   // array to be sorted
    size_t n = sizeof a / sizeof a[0];       // number of elements

    for (size_t i = 0; i < n - 1; ++i) {
        int count = 0;                       // 周の最初に0へ戻す
        for (size_t j = 0; j < n - 1 - i; ++j) {
            if (cmp(a[j], a[j+1])) {
                swap( &a[j] , &a[j+1] );
                count++;                     // 入れ替えたら+1
            }
        }
        if (count == 0) {                    // 入れ替え0回なら整列完了
            break;
        }
    }

    for (size_t i = 0; i < n; ++i) {
        printf("%d ", a[i]);
    }
    printf("\n");

    return 0;
}

/*
①21行目の下にint count =0;
②if (cmp( ? , ? )) {swap( ? , ? );}の{}中にcount++;
③26行目の下にif (count == 0){break;}
なお、今回においてはcountで数える必要がないため、++count;の行はcount =1;；に置き換え、ON/OFF判定にすることも可能である。
*/