Advertisement
JosepRivaille

P42672: Barrejant en base 2

Apr 4th, 2015
541
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. //Barrejar es escriure una xifra de cada nombre
  5. void canvi_i_barreja(int a, int b) {
  6.     if (a != 0 or b != 0) {
  7.         canvi_i_barreja(a/2, b/2);
  8.         cout << a%2;
  9.         cout << b%2;
  10.     }
  11. }
  12.  
  13. //Pre: Llegeix 2 enters
  14. //Post: Els converteix a binari i els barreja
  15. int main(){
  16.     int a, b;
  17.     while (cin >> a >> b) {
  18.         canvi_i_barreja(a, b);
  19.         cout << endl;
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement