Advertisement
JosepRivaille

P72315: Intercalació de nombres

Apr 6th, 2015
658
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.40 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. int intercalacio(int x, int y) {
  6.     int i = 0;
  7.     int mult = 1;
  8.     while (x != 0 or y != 0) {
  9.         i = mult*((y%10) + (x%10)*10) + i;
  10.         mult = mult *100;
  11.         x = x/10;
  12.         y = y/10;
  13.     }
  14.     return i;  
  15. }
  16.  
  17. //Pre: Llegeix 2 naturals
  18. //Post: Els escriu intercaladament
  19. int main() {
  20.     int x, y;
  21.     while (cin >> x) {
  22.         cin >> y;
  23.         cout << intercalacio(x, y) << endl;
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement