#include <stdio.h>

int cmp(int x, int y) 
{
    return x > y; 
}

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}; 
    size_t n = sizeof a / sizeof a[0];     
    size_t count = 0;                     

    for (size_t i = 0; i < n - 1; ++i) {
        for (size_t j = 0; j < n - 1 - i; ++j) {
            if (cmp(a[j], a[j + 1])) {
                swap(&a[j], &a[j + 1]);
                ++count;                  
            }
        }
    }

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

    return 0;
}