Advertisement
apl-mhd

divide and conqure negative in array

Mar 15th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3.  
  4. using namespace std;
  5.  
  6. int count(int A[], int start, int end){
  7.  
  8.     if(start == end){
  9.  
  10.         if(A[start] <0)
  11.             return  1;
  12.         else
  13.             return 0;
  14.  
  15.  
  16.     }
  17.  
  18.     int mid = (start +end) /2;
  19.  
  20.     return count(A, start, mid) + count(A, mid+1, end);
  21.  
  22. }
  23.  
  24. int main() {
  25.  
  26.  
  27.     int A[] ={1,-2,3,-5,6};
  28.  
  29.     cout<<count(A, 0, 3)<<endl;
  30.  
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement