Advertisement
Dizzy3113

Untitled

Nov 17th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int numar(int n, int c1, int c2)
  6. {
  7. int r=0;
  8. int p=1;
  9.  
  10. while(n)
  11. {
  12. if(n%10==c1)
  13. {
  14. r=r+p*c2;
  15. p=p*10;
  16. n=n/10;
  17. } else
  18. {
  19. r=r+p*(n%10);
  20. p=p*10;
  21. n=n/10;
  22. }
  23.  
  24.  
  25. }
  26. return r;
  27. }
  28. int main()
  29. {
  30. cout<<numar(14944, 4, 2);
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement