title: How to create loops for ordering vectors
body: <p>I have a homework problem that asks for my code to read a 10-length vector, order it in ascendant order and then print it. I'm trying to do this using a variable int k as a countable index, where the code verifies whether a particular position in the vector is greater than the other positions, and adds 1 to k for each smaller variable. Then, I create a second vector, and atrribute for its kth position this value of the first vector.
  The compilation isn't pointing out any mistakes. The code runs, I inform the 10 values of the vector, then it returns a big number and crashes.
  Could anyone help me? Thanks in advance.</p>
  
  <pre class="lang-c prettyprint-override"><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;locale.h&gt;
  
  int main ()
  {
      setlocale(LC_ALL, "Portuguese");
      //creates two double vectors
      double v[10], w[10];
      //creates a int variable to be a countable index
      int k = 0;
      //asks for the user to inform the values of the vector
      for (int i=0; i&lt;=9; i++)
      {
          printf("Digite um número:\n");
          scanf("%lf", &amp;v[i]);
      }
      //Here, I create this loop to verify whether each position of the vector v is greater than the other positions.
      for (int j=9; j&gt;=0; j--)
      {
          //For the case j=9, I verify if it is greater than all the predecessor values, and add 1 to k for each case
          if (j==9)
          {
              for (int t=j-1; t&gt;=0; t--)
              {
                  if (v[j]&gt;v[t])
                  {
                      k+=1;
                  }
              }
              //I attribute this value of v to the kth position of the new vector, and restart the countable index
              w[k]=v[j];
              k=0;
              continue;
          }
          //I do the same for the case in which j=0, verifying whether it is greater than the subsequent values
          else if (j==0)
          {
              for (int s=j+1; s&lt;=9; s++)
              {
                  if (v[j]&gt;v[s])
                  {
                      k+=1;
                  }
              }
              w[k]=v[j];
              k=0;
              continue;
          }
          //For all the other values of the vector, I test both whether they are greater than the
          //predecessors and the subsequent values, and add 1 to k for each case
          else
          {
              for (int t=j-1; t&gt;=0; t--)
              {
                  if (v[j]&gt;v[t])
                  {
                      k+=1;
                  }
              }
              for (int s=j+1; s&lt;=9; s--)
              {
                  if (v[j]&gt;v[s])
                  {
                      k+=1;
                  }
              }
              //I attribute this value to the kth position of the new vector and restart the countable index
              w[k]=v[j];
              k=0;
  
          }
      //Here my loop ends
      }
      //I print the new vector
      for (int p=0; p&lt;=9; p++)
      {
          printf(" %lf ",w[p]);
      }
      system("pause");
      return 0;
  }
  
  </code></pre>