Sign in to follow this  
Cornel Iulian

[C++] Inlocuirea a 2 cifre intr-un numar

1 post in this topic

Se citeste un numar natural n si 2 cifre c1 si c2. Sa se inlocuiasca c1 cu c2

 

#include <iostream>
using namespace std;
int main()
{
    int n,c1,c2,nr=0,p=1;
    cout<<"N = "; cin>>n;
    cout<<"C1 = "; cin>>c1;
    cout<<"C2 = "; cin>>c2;

    while(n!=0)
    {
        if(n%10==c1)
            nr=nr+c2*p;
        else
            nr=nr+(n%10)*p;
        p*=10;
        n/=10;
    }
    cout<<nr;

    return 0;
}

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this