ValerianBenchea

DIVIDE ET IMPERA cate cifre impare intr-un vector

Nov 16th, 2021
905
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int v[21];
  4. int n;
  5. int impar(int st, int dr)
  6. {
  7.     if(st==dr)
  8.     {
  9.         if(v[st]%2==1)
  10.             return 1;
  11.         else
  12.             return 0;
  13.     }
  14.     else
  15.     {
  16.         int mij=(st+dr)/2;
  17.         int P1=impar(st, mij);
  18.         int P2=impar(mij+1, dr);
  19.             return P1+P2;
  20.     }
  21. }
  22.  
  23. int main()
  24. {
  25.     cin>>n;
  26.     for(int i=1; i<=n; i++)
  27.         cin>>v[i];
  28.     cout<<impar(1, n);
  29.     return 0;
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment