Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int v[100];
- void citire (int n)
- {
- for (int i=1;i<n+1;i++)
- cin>>v[i];
- }
- int f (int s,int d,int &sum)
- {
- if (s==d)
- {
- sum+=v[s];
- return v[s];
- }
- else {
- int m=(s+d)/2;
- return f(s,m,sum)*f(m+1,d,sum);
- }
- }
- int main()
- {
- int n, sum=0;
- cin>>n;
- citire(n);
- cout<<"produs: "<<f(1,n,sum)<<endl;
- cout<<"suma: "<<sum;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement