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.

my code:

```
#include <iostream>
using namespace std;

int main()
{
  long  int n;
    cin>>n;
  long  int a[n];
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
     }
     for (int i=1;i<=n;i++)
    {

               while(a[i]==i&&a[i]==-1)
               {
                   int temp=a[i];
                   a[i]=a[temp];
                   a[temp]=temp;
               }

    }

    for(int i=1;i<=n;i++)
        cout<<a[i]<<" ";
    return 1;

```

}

output:

```
6
-1 4 2 3 -1 5
-1 4 2 3 -1 5

```

can anyone please help me in finding out my error in the logic apllied?
Thanks in advance.