Test Case 0,1,2 is passed.3,4 is not…First tell me whats wrong in my code and then rectify it pls
#include
using namespace std;
int invert(int n){
int p=0;
int a=1;
while(n!=0){
int ld=n%10;
if(n==9){
p=p+(ld*a);
break;
}
int newn=9-ld;
if(newn<ld){
p=p+(newn*a);
}
else{
p=p+(ld*a);
}
n=n/10;
a=a*10;
}
return p;
}
int main() {
int n;
cin>>n;
cout<<invert(n)<<endl;
return 0;
}