Failed test cases

i am not getting why is my code failing few of the test cases. please help me!!

#include
using namespace std;

int main()
{
int n;
cin>>n;
int check=0;
int recheck=0;
int alt;
alt =n;
while(alt>0)
{
check++;
alt=alt/10;

}
alt = n;
int arr[check+1000];
for(int i=check-1; i>=0; i--)
{
    arr[i]=(alt%10);
    alt = alt/10;
}
for(int i=0; i<check; i++)
{
    if((9-arr[i])<arr[i])
    {
        arr[i]=9-arr[i];
    }
}
for(int i=0; i<check; i++)
{
    if(arr[i]==0)
    {
        recheck++;
    }
    else
    {
        i =(check-1);

    }
}
for(int i=0; i<recheck; i++)
{
    arr[i] = (9-arr[i]);
}

for(int i=0; i<check; i++)
{
    cout<<arr[i];
}

return 0;

}

@saurabh66 share your code using cb ide please

input 998
ans 901
your o/p 991 check it

that i corrected.
i wanted to ask in case if input is a negative integer can i calculate the answer after making it positive.
i tried doing it but still my code fail 2 cases.
plz explain what should i do for the negative number.

this is the updated code.

@saurabh66 check for this
932711047202

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.