What is problem in this?

You are doing n = n / 10 in the loop until it’s zero, how do expect correct answer later by using the same n.

i am not using the n again…i am storing it in array

Please store it in a temp variable first, so that you do not lose the original n after,

	while(n!=0){
		n%10;
		n=n/10;
		c++;
	}

https://ide.codingblocks.com/s/326274…1tc is failed?

I can debug it but, also note that there is a better approach for this, which makes it very simple to solve and code.

Just use a string instead of int and replace every character ‘c’ with min(c, ‘9’ - c + ‘0’);

The error is for a case like, 54, your code will not change ‘5’ as i == 0, but the answer should be 44.

https://ide.codingblocks.com/s/326274…i have updated whats the error now?

also tell better approach of how to do it using string

No, it is still not correct.
Try the code for ‘54’ and you’ll see why?

Yes, please see the following,

#include<bits/stdc++.h>
using namespace std;

int main()
{
	string n;
	cin >> n;
	if (n[0] != '9') { n[0] = min(n[0], char(('9' - n[0]) + '0')); }
	for (int i = 1; i < n.size(); ++i) {
		n[i] = min(n[i], char(('9' - n[i]) + '0'));
	}
	cout << n;
	return 0;
}