Advertisement
STANAANDREY

sume_partiale_vectori

Jun 6th, 2019
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.37 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.  
  8.     unsigned long v[100], s[100], n, i, st, dr;
  9.     cout << "interval(st<dr):";
  10.     cout << "st=";
  11.     cin >> st;
  12.     cout << "dr=";
  13.     cin >> dr;
  14.     cout << "n=";
  15.     cin >> n;
  16.     for (i = 0; i < n; i++)
  17.         cin >> v[i];
  18.     cout << endl;
  19.     s[0] = v[0];
  20.     for (i = 1; i < n; i++)
  21.         s[i] = s[i - 1] + v[i];
  22.     for (i = 0; i < n; i++)
  23.         cout << s[i] << ' ';
  24.     cout << endl;
  25.     cout << "suma:" << s[dr] - s[st - 1];
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement