Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Сумма сегмента массива*/
- #include <iostream>
- using namespace std;
- void sum(int* array) {
- int s = 0;
- int start, finish;
- cout << "Введите индекс начала сегмента: ";
- cin >> start;
- cout << "Введите индекс конец сегмента: ";
- cin >> finish;
- for (int i = start - 1; i < finish; i++) {
- s += array[i];
- }
- cout << "Сумма сегмента массива от " << start << " до " << finish << " равна " << s << endl;
- }
- int main() {
- int size;
- setlocale(LC_ALL, "Russian");
- cout << "Введите размер массива: ";
- cin >> size;
- int* array = new int[size];
- for (int i = 0; i < size; i++) {
- cout << "Введите " << i + 1 << " элемент массива: ";
- cin >> array[i];
- }
- sum(array);
- delete array;
- }
Add Comment
Please, Sign In to add comment