title: How to count number of swaps in a bubble sort?
body: <p>So I need my program to print the values entered and count the number of swaps(not comparisons). So far I have everything working except the swap counter. I tried just incrementing by using <code>swap++;</code> in my if statement along with the bubble sort but that doesn't work. Any ideas? Here is my code.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int sort(int array[], int count);
  
  int main(void) {
  
      int numArray[100];
      int counter, value;
  
      printf("Enter array length \n");
      scanf("%d", &amp;counter); 
  
      int i = 0;
      while(i &lt; counter){
          scanf("%d", &amp;numArray[i]);
          i++;    
      }
  
      i = 0;
      while(i &lt; counter) {
          sort(numArray, counter);
          i++;
      }
  
      int totalSwaps = sort(numArray, counter);
      printf("Swaps: %d\n", totalSwaps); 
  
      i = 0;
      while(i &lt; counter) {
          printf("Values: %d\n", numArray[i]); 
          i++;
      }
  
      return 0;
  }
  
  int sort(int array[], int count) {
      int i, j, temp;
      int swaps = 0;
      for(i = 0; i &lt; count-1; ++i) {
          for(j=0; j &lt; count-1-i; ++j) {
              if(array[j] &gt; array[j+1]) {
                  temp = array[j+1];
                  array[j+1] = array[j];
                  array[j] = temp;
                  swaps++;
              }
          }
      }
  
      return swaps;
  }
  </code></pre>