I am getting segmentation error . Please tell whats wrong in my code. The logic i applied looks fine to me idky am i getting segmentation error

hi @akshat1409 your approach is little bit wrong

  1. first right like this
int a[n];
int b[n];
  1. Inverse is Simply swapping the value of the array with the value at that index.

Algo

  1. Create a new Array say narr and original array is arr.
  2. now at the arr[i]th index of narr save the ith value.(previously i is the index and arr[i] is the value bt now arr[i] is the index and i is the value.)
  3. return new array.

refer this code ->

#include<bits/stdc++.h>
using namespace std;
int main() {
   int N;
   cin>>N;
   int a[N];
   for(int i =0;i<N;i++)
   	cin>>a[i];
   int b[N];
   for(int j=0;j<N;j++){
   	b[a[j]]=j;
   }
   for(int i=0;i<N;i++){
       cout<<b[i]<<" ";
   }
   return 0;
}

what is the meaning of <bits/stdc++.h> ; cin>>N;( we take in value by cin>> not cin&gt ; int i =0;i<N;i++

all of this has not been taught yet. Can you please Please give a simpler code for this which doesnt use &gt and stuff

even in my approach i was making a new array the same way. Where did i go wrong? Please correct my code i am unable to understand urs

hi @akshat1409 <bits/stdc++.h> includes all libraries at once, rest things is same as u use

whats the meaning of cin>>N;

@akshat1409 u r taking value of N as input from user

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.