title: Insertion sort - counting of comparisons and swaps in C
body: <p>how can I count number of comparisons and swaps in insertion sort? I have array with 10 random numbers. If somebody help me how to put also 20, 50, 100, 200, 500, 1000, 2000 and 5000 random numbers in this program I will be very happy. I have been thinking of this for a long time and still cannot find solution.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;time.h&gt;            
  int main()
  {
  
      int array[10];
      int i, j, n, temp;
      n = 10;
      for (i = 0; i &lt; n; i++)
          array[i] = rand();
  
      /*Sort*/
      for (i = 1; i &lt; n; i++) {
          j = i;
          while ((j &gt; 0) &amp;&amp; (array[j - 1] &gt; array[j])) {
              temp = array[j - 1];
              array[j - 1] = array[j];
              array[j] = temp;
              j--;
          }
      }
      /* Print */
      printf("Sorted Array\n");
      for (i = 0; i &lt; n; i++)
          printf("%d \n", array[i]);
      return 0;
  }
  </code></pre>