ValerianBenchea

Daca doua cifre au aceeasi paritate sau nu

Mar 2nd, 2020
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int a, b, cnt1=0, cnt2=0, c;
  8.     bool p=1, k=1;
  9.     cout<<"a="; cin>>a;
  10.     cout<<"b="; cin>>b;
  11.     if(a%2==0)
  12.         p=1;
  13.     else
  14.         p=0;
  15.     if(b%2==0)
  16.         k=1;
  17.     else
  18.         k=0;
  19.     if(p==k)
  20.     {
  21.        while(a)
  22.        {
  23.            c=a%10;
  24.            if(c%2==0)
  25.                 cnt1++;
  26.            a/=10;
  27.        }
  28.        while(b)
  29.        {
  30.             c=b%10;
  31.            if(c%2==0)
  32.                 cnt1++;
  33.            b/=10;
  34.        }
  35.     }
  36.     if(cnt1)
  37.         cout<<cnt1<<"\n";
  38.     if(p!=k)
  39.     {
  40.        while(a)
  41.        {
  42.            c=a%10;
  43.            if(c%2==1)
  44.                 cnt2++;
  45.            a/=10;
  46.        }
  47.        while(b)
  48.        {
  49.             c=b%10;
  50.            if(c%2==1)
  51.                 cnt2++;
  52.            b/=10;
  53.        }
  54.     }
  55.     if(cnt2)
  56.         cout<<cnt2;
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment