The code is throwing segmentation error. How can I resolve this? Is this approach wrong?

#include<bits/stdc++.h>
using namespace std;

void Chewbacca(int a[], int n){
for(int i=n-1;i>=0;i–){
if(a[n-1]==9){
continue;
}
if(a[i]>9-a[i]){
a[i]=9-a[i];
}
}
for(int j=n-1;j>=0;j++){
cout<<a[j];
}
}
int main() {
int num,arrays[100];
cin>>num;
int i=0;
while(num!=0){
int rem=0;
rem=num%10;
arrays[i]=rem;
i++;
num=num/10;
}
int N=i-1;
Chewbacca(arrays,N);
return 0;
}

hello @agarwal_prachi

hre it should be i only.

try this , if it again fails then pls save ur code at cb ide and share its link with me

Still same error. Here is the link. https://ide.codingblocks.com/s/488059

check now

Thankyou for resolving the doubt!

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.