Chewbacca number (correct code but failing two test cases)

I am failing two test cases in this one plz teel my mistake

include

using namespace std;

define int long long

int chewbaccanum(int n){
int no = 0,i=1;
while (n!=0)
{
int digit = n%10;
int newdigit = 9 - digit;
if (newdigit<digit)
{
no += newdigiti;
}
else
{
no += digit
i;
}

   i *= 10;
   n /= 10; 
}
return no;

}

int32_t main(){
int n;
cin>>n;
cout<<chewbaccanum(n);
return 0;
}

@abhinavssr2003_eab0717682969e5c, check for 999
ans should be 900
our output is 0

why the hundred’s place nine is not getting 0???

ohh got it…it shouldn’t start with 0

@abhinavssr2003_eab0717682969e5c yeah exactly

1 Like

@abhinavssr2003_eab0717682969e5c if doubt is clear please mark it resolved

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.