ToniDev

Verificare 3 cifre impare consecutive dintr-un numar

Sep 25th, 2023
623
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. unsigned short verificareTreiCifreAlaturateImpare(int n)
  8. {
  9.     int gasite = 0;
  10.  
  11.     while (n > 0)
  12.     {
  13.         if (gasite == 3)
  14.         {
  15.             break;
  16.         }
  17.  
  18.         int ultimaCifra = n % 10;
  19.  
  20.         if (ultimaCifra % 2 != 0)
  21.         {
  22.             gasite++;
  23.         }
  24.         else
  25.         {
  26.             gasite = 0;
  27.         }
  28.  
  29.         n /= 10;
  30.     }
  31.  
  32.     if (gasite == 3) return 1;
  33.     else return 0;
  34. }
  35.  
  36. int main()
  37. {
  38.     cout << verificareTreiCifreAlaturateImpare(23334) << endl;
  39.  
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment