DEV Community

Carnato
Carnato

Posted on

All '0' Replace with '5'

Solution of the problem

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n=1005;
    int ans=n;
    int p=1;
    while(n)
    {
        if(n%10==0)
        {  
         ans=ans+p*5;
        }
        n/=10;
        p=p*10;
    }
    cout<<ans;
    return 0;
}
Enter fullscreen mode Exit fullscreen mode

Discussion (0)