Chewbacca and number,test case 2 and 3 not working

#include
using namespace std;
int main() {

int i,n2,n1;
cin>>n2;
if((n2>= 1)&&(n2<= 100000000000000000))

{
i=0;
long long int d[1000000];
n1=n2;
while(n1!=0)
{
d[i]=n1%10;
n1=n1/10;
i++;
}

for(int j=0;j<i/2;j++)
swap(d[j],d[i-1-j]);

int j=0;
int n=9-d[j];
if(n>0&&(d[j]>n))
{
d[j]=n;
}

for(int j=i;j<i;j++)
{n =9-d[j];
if(d[j]>n)
d[j]=n;

}

for(j=0;j<i;j++)
cout<<d[j];

}
return 0;
}

Hello @lovepreet_singh check for the sample test case only your code is not producing the correct result.
check your logic again.
if you have any doubt you can ask here:
Happy Learning!!

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.