edutedu

divide timpera maximul

Feb 19th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int n, a[100];
  5. int maxdiv(int st, int dr)
  6. {
  7. int m, max1, max2;
  8. if(st==dr)
  9. return a[st];
  10. else
  11. {
  12. m=(st+dr)/2;
  13. max1=maxdiv(st,m);
  14. max2=maxdiv(m+1, dr);
  15. if(max1>=max2)
  16. return max1;
  17. else
  18. return max2;
  19. }
  20. }
  21. int main()
  22. {
  23. int i;
  24. cin>>n;
  25. for(i=1; i<=n; i++)
  26. cin>>a[i];
  27. cout<<"max="<<maxdiv(1,n);
  28. return 0;
  29. }
Add Comment
Please, Sign In to add comment