Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int n, a[100];
- int maxdiv(int st, int dr)
- {
- int m, max1, max2;
- if(st==dr)
- return a[st];
- else
- {
- m=(st+dr)/2;
- max1=maxdiv(st,m);
- max2=maxdiv(m+1, dr);
- if(max1>=max2)
- return max1;
- else
- return max2;
- }
- }
- int main()
- {
- int i;
- cin>>n;
- for(i=1; i<=n; i++)
- cin>>a[i];
- cout<<"max="<<maxdiv(1,n);
- return 0;
- }
Add Comment
Please, Sign In to add comment