Advertisement
apl-mhd

max in the array using recursion

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