Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,885 questions

51,811 answers

573 users

How to replace all ‘0’ in a number with specific digit in C++

1 Answer

0 votes
#include <iostream>

using namespace std;

int convert_0_To_n__(int number, int d) { 
    if (number == 0) 
        return 0; 
  
    int digit = number % 10; 
    if (digit == 0) 
        digit = d; 
  
    return convert_0_To_n__(number / 10, d) * 10 + digit; 
} 
int convert_0_To_n(int number, int d) { 
    if (number == 0) 
        return d; 
    else 
        return convert_0_To_n__(number, d); 
} 

int main() 
{ 
    int number = 1080030; 
    
    cout << convert_0_To_n(number, 7); 
    
    return 0; 
}



/*
run:

1787737

*/

 



answered Apr 19, 2019 by avibootz
edited Apr 20, 2019 by avibootz

Related questions

1 answer 148 views
1 answer 155 views
1 answer 161 views
1 answer 122 views
1 answer 185 views
...