#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
    int count=0;
    int forcount=0;
    int fornaicount=0;

    for (size_t i = 0; i < n - 1; ++i) {
        fornaicount=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++;
               fornaicount++;
          
            }
         forcount++;
      }
   if(fornaicount==0){
         break;
}
    }

    printf("swapの回数%d\n",count);
    printf("21行目の繰り返し回数%d\n",forcount);

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

    return 0;
}
