Replace all 0's in a number by 5

i did this but its printing in reverse order . how to resolve that

#include
using namespace std;

int main()
{

int n;

cin>>n;
int r;
int rep=5;
int d=1;
for(int i=n;i>0;i=i/10)
{
    r=i%10;
    if(r==0)
    {
        r=rep*d;
    }
    else
    {
        r=r*d;
    }
    cout<<r<<"";
}

}

suppose i put 1001
then output is fine which is 1551 but with regular number its printing in reverse order

u have 2 alternates to this problem

either reverse the resultant number again

or
convert it to string and then replace the ‘0’ then convert the string it back to int

Either reverse the number :
Tell me how to do that. I cannot .
Secondly converting into string I’ll try

How to reverse the number I created after replacing with 5. That’s the doubt ?

see
in the while loop u traverse from last digit
eg
2014101
u take digit 1 => u print out 1
then 2nd digit extracted is 0 u replace to 5 => u print out 5
then 1 => print out 1
then 4 is extracted =>print out 4

basically u started traversing from units place and printing from starting units place so the number printed in reversed

start traversing from left most digit then the reverse wont be printed

But I tried this using for loop and I don’t think there is any method from which we can start traversing a number from left most without an array used ?

nope i too havent ever came across a technique of traversing the integer from left side

that is why i recomedded to convert to string

Converting to string will require more complex code in c++. Isn’t it ? By using string stream ? Any other method

use c++ stl functino
string ans = to_string(num)

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.