TEXT   7
Untitled
Guest on 17th March 2023 01:04:00 PM


  1. #include <iostream>
  2. using namespace std;
  3. int cifreImpare(int n) {
  4.     int cifra, nou = 0, impare = 0,ok=0;
  5.  
  6.     while (n != 0) {
  7.         cifra = n % 10;
  8.         n /= 10;
  9.          ok++;
  10.         if (cifra % 2 == 0) {
  11.             nou = nou * 10 + cifra;
  12.         } else {
  13.             impare++;
  14.         }
  15.     }
  16.  
  17.     if (impare == 0|| ok==impare) {
  18.         return -1;
  19.     } else {
  20.         int invers = 0;
  21.         while (nou != 0) {
  22.             cifra = nou % 10;
  23.             nou /= 10;
  24.             invers = invers * 10 + cifra;
  25.         }
  26.         return invers;
  27.     }
  28. }
  29. int main()
  30. {
  31.     int n;
  32.     cin>>n;
  33.     cout << cifreImpare(n) << endl;
  34.     return 0;
  35. }

Raw Paste

Login or Register to edit or fork this paste. It's free.