Pleasedebug my problem in my code
- As x <= 100000000000000000 so instead of int you have to use long int.
- When you are doing 9-str[i] then it is using asci value of str[i] which is why it is printing unknown characters. Instead you should first find the int value of str[i] by x=str[i]-‘0’ and then check if 9-x<x or not. And for storing this value at str[i] you have to use str[i]=(9-x)+‘0’;.
- You also have to include the case when str[0]==9 because if we use 9-x formula then str[i] will become 0 and in the ques it is mentioned that the new number should not have leading zeros.
Here is your corrected code :