Sa se calculeze folosind metoda divide et impera suma elementelor unui vector

suma

#include<iostream.h>
int v[20],n;
int suma(int li,int ls)
{int m, d1 ,d2;
 if(li!=ls)           
     {m=(li+ls)/2;
      d1=suma(li,m); 
      d2=suma(m+1,ls);
       return d1+d2;
      }
 else 
    return v[li];
}
     
void main() 
{           
 cout<<"n=";
 cin>>n;    
 for(int i=1;i<=n;i++)
   {cout<<"v["<<i<<"]=";
    cin>>v[i];}
cout<<"suma celor "<<n<<" elemente ale vectorului "<<suma(1,n);
}