title: C: I made a program to sort an array in ascending order and cannot figure the reason for a certain step in the for loops
body: <p>I am making a program to sort numbers in an array using the bubble sort method in c and I know how to do it but I cannot figure out what the second for loop's <code>j&lt;n-i-1</code>subtraction of i from the length of the array is for. It is probably a simple explanation but I cannot for the life of me scramble my small brain for the answer.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main()
  {
      int input[10],swap;
      printf("Input Numbers: ");
      scanf("%d%d%d%d%d%d%d%d%d%d",&amp;input[0],&amp;input[1],&amp;input[2],&amp;input[3],&amp;input[4],&amp;input[5],&amp;input[6],&amp;input[7],&amp;input[8],&amp;input[9]);
      int n=10;
      for(int i=0;i&lt;n-1;i++){
          for(int j=0;j&lt;n-i-1;j++){
              if(input[j]&gt;input[j+1]){
                  swap=input[j];
                  input[j]=input[j+1];
                  input[j+1]=swap;
              }
          }
      }
      printf("Sorted List: {");
      for(int i=0;i&lt;10;i++){
          if(i&lt;9){
              printf("%d, ",input[i]);
          }
          else{
              printf("%d}",input[i]);
          }
      }
      return 0;
  }
  </code></pre>