title: cant find error in my applied logic
body: <p>question:
  Given an array of elements of length N, ranging from 0 to N-1, your task is to write a program that rearranges the elements of the array. All elements may not be present in the array, if element is not present then there will be -1 present in the array. Rearrange the array such that A[i] = i and if i is not present, display -1 at that place.</p>
  
  <p>my code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  int main()
  {
    long  int n;
      cin&gt;&gt;n;
    long  int a[n];
      for(int i=1;i&lt;=n;i++)
      {
          cin&gt;&gt;a[i];
       }
       for (int i=1;i&lt;=n;i++)
      {
  
  
                 while(a[i]==i&amp;&amp;a[i]==-1)
                 {
                     int temp=a[i];
                     a[i]=a[temp];
                     a[temp]=temp;
                 }
  
  
      }
  
      for(int i=1;i&lt;=n;i++)
          cout&lt;&lt;a[i]&lt;&lt;" ";
      return 1;
  </code></pre>
  
  <p>}</p>
  
  <p>output:</p>
  
  <pre><code>6
  -1 4 2 3 -1 5
  -1 4 2 3 -1 5
  </code></pre>
  
  <p>can anyone please help me in finding out my error in the logic apllied?
  Thanks in advance.</p>