Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*sa se scrie un program ce foloseste metoda DEI pt a calcula suma dintr-un vector*/
- #include <iostream>
- #define NMAX 1000
- using namespace std;
- int n, v[NMAX];
- void read() {
- cin >> n;
- for (int i = 0; i < n; i++)
- cin >> v[i];
- }
- int getsum(int p, int q) {
- if (p == q)
- return v[p];
- int mid = (p + q) / 2;
- return getsum(p, mid) + getsum(mid + 1, q);
- }
- int main() {
- read();
- cout << getsum(0, n - 1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement