Advertisement
frentzy

ParImpar

Jul 30th, 2020 (edited)
1,473
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <conio.h>
  2. #include <stdio.h>
  3. #include <iostream>
  4. #include <math.h>
  5. #include <algorithm>
  6. using namespace std;
  7.  
  8. #define PAR (!((numar % 10) % 2))
  9. #define IMPAR (((numar % 10) % 2))
  10.  
  11. int ParImpar(bool par,int numar) {
  12.     int finalPar = 0, produs = 1;
  13.     while (numar) {
  14.         if (par ? PAR : IMPAR) {
  15.                
  16.             finalPar = finalPar + numar % 10 * produs;
  17.             produs *= 10;
  18.                
  19.             numar /= 10;
  20.         }  
  21.         else {
  22.             numar /= 10;
  23.         }
  24.     }
  25.     return finalPar;
  26. }
  27.  
  28. void main() {
  29.     int numar1, numar2,rez1,rez2;
  30.  
  31.     cin >> numar1;
  32.     rez1 = (numar1 % 2 == 0 ) ? ParImpar(true, numar1) : ParImpar(false, numar1);
  33.     cin >> numar2;
  34.     rez2 = (numar2 % 2 == 0) ? ParImpar(true, numar2) : ParImpar(false, numar2);
  35.  
  36.     cout << ((rez1 == rez2) ? ((numar1 > numar2) ? numar1 : numar2) : (rez1 > rez2) ? numar1 : numar2);
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement