Advertisement
rotti321

SumVec

Mar 30th, 2022
57
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int divide_impera(int v[],int st,int dr){
  5. int mij;
  6. if(st==dr){
  7. return v[st];
  8. }
  9. if(st+1==dr){
  10. return v[st]+v[dr];
  11. }
  12. mij=(st+dr)/2;
  13. return divide_impera(v,st,mij)+divide_impera(v,mij+1,dr);
  14. }
  15.  
  16. int main() {
  17. int n,v[1001]={},st,dr;
  18. cin>>n;
  19. for(int i=1; i<=n; i++){
  20. cin>>v[i];
  21. }
  22. st=1;
  23. dr=n;
  24. cout<<divide_impera(v,st,dr);
  25. return 0;
  26. }
  27. /*
  28. 6
  29. 4 3 5 7 6 8
  30.  
  31. */
Advertisement
RAW Paste Data Copied
Advertisement