title: Sorting an array to another array C++
body: <p>My program have to sort an array in another array.
  When I run the program it prints 1 2 3 -858993460 5 -858993460 7.
  I can not understand where the mistake is in the code.</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  int main()
  {
     const int N = 7;
     int arr[N] = { 3, 17, 2, 9, 1, 5, 7 };
  
     int max = arr[0];
     for (int i = 1; i &lt; N; i++)
     {
         if (max &lt; arr[i]) 
             max = arr[i];
     }
     int sort_arr[N];
     for (int j = 0; j &lt; N; j++)
     {
         sort_arr[arr[j] - 1] = arr[j];
     }
  
     for (int i = 0; i &lt; N; i++)
     {
         cout &lt;&lt; sort_arr[i] &lt;&lt; " ";
     }
  
     return 0;
  }
  </code></pre>