Вопрос задан 03.05.2019 в 21:07. Предмет Информатика. Спрашивает Коняшова Маруся.

дан вектор b[1:10] а)найти минимальный и максимальный элементы вектора.,)поменять местами

максимальный и минимальный элементы. в)получить сумму элементов между их номерами.г)Получить произведение отрицательных элементов. Помогите пожалуйста.
0 0
Перейти к ответам

Ответы на вопрос

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Ратникова Дарья.
Uses crt;
var b:array [1..10] of real;
    min,max,x:integer;
    sum,pr,t:real;
begin
     sum:=0; pr:=1;
     for x:=1 to 10 do
     begin
          write('b[',x,']:'); readln(b[x]);
     end;
     min:=1; max:=1;
     for x:=1 to 10 do
     begin
         if b[x]<b[min] then min:=x;
         if b[x]>b[max] then max:=x;
     end;
     t:=b[min];
     b[min]:=b[max];
     b[max]:=t;
     if max>=min then
     for x:=min+1 to max-1 do
         sum:=sum+b[x]
     else
     for x:=max+1 to min-1 do
         sum:=sum+b[x];
     for x:=1 to 10 do
         if b[x]<0 then pr:=pr*b[x];
     for x:=1 to 10 do
         write(b[x],' ');
     writeln; writeln(sum);
     writeln(pr);
end.    
0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

Finding the Minimum and Maximum Elements of a Vector

To find the minimum and maximum elements of a vector, you can use the `min()` and `max()` functions in most programming languages. Here's an example in Python:

```python b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] min_element = min(b) max_element = max(b) ```

In this example, the `min()` function returns the minimum element of the vector `b`, which is 1, and the `max()` function returns the maximum element, which is 10.

Swapping the Maximum and Minimum Elements

To swap the positions of the maximum and minimum elements in a vector, you can find their indices and then swap the elements at those indices. Here's an example in Python:

```python b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] min_element = min(b) max_element = max(b) min_index = b.index(min_element) max_index = b.index(max_element) b[min_index], b[max_index] = b[max_index], b[min_index] ```

In this example, the `index()` function is used to find the indices of the minimum and maximum elements. Then, the elements at those indices are swapped using a tuple assignment.

Getting the Sum of Elements between their Indices

To get the sum of elements between the indices of the minimum and maximum elements in a vector, you can use a loop to iterate over the elements within that range and accumulate their sum. Here's an example in Python:

```python b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] min_element = min(b) max_element = max(b) min_index = b.index(min_element) max_index = b.index(max_element) sum_elements = 0 for i in range(min_index + 1, max_index): sum_elements += b[i] ```

In this example, the loop iterates over the elements between the indices `min_index + 1` and `max_index - 1` (excluding the minimum and maximum elements themselves) and accumulates their sum in the `sum_elements` variable.

Getting the Product of Negative Elements

To get the product of the negative elements in a vector, you can iterate over the elements and multiply them together if they are negative. Here's an example in Python:

```python b = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10] product_negative = 1 for element in b: if element < 0: product_negative *= element ```

In this example, the loop iterates over each element in the vector `b` and multiplies it with the `product_negative` variable if the element is negative.

I hope this helps! Let me know if you have any further questions.

0 0

Топ вопросов за вчера в категории Информатика

Последние заданные вопросы в категории Информатика

Задать вопрос