Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include <stdafx.h>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. void scan(int *Arr, int N)
  6. {
  7. for (int i = 0; i<N; i++)
  8. {
  9. cout << "Введите " << i << " элемент массива: ";
  10. cin >> Arr[i];
  11. }
  12. }
  13. void sum_el(int *Arr, int N, int L, int K, int sum = 0)
  14. {
  15. for (int i = K; i <= L; i++)
  16. {
  17. sum = sum + Arr[i];
  18. }
  19. cout << "Сумма элементов указанного диапазона" << endl;
  20. cout << sum << endl;
  21. }
  22.  
  23. int main()
  24. {
  25. setlocale(LC_ALL, "rus");
  26. int* Arr;
  27. int N, K, L, sum;
  28. cout << "Введите количество элементов N массива: " << endl;
  29. cin >> N;
  30. Arr = new int[N];
  31. scan(Arr, N);
  32. cout << "Введите две необходимые позиции в массиве K <= L " << endl;
  33. cin >> K >> L;
  34. sum_el(Arr, N, K, L, sum);
  35. delete[] Arr;
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement