Вопрос задан 10.08.2018 в 01:17. Предмет Информатика. Спрашивает Гинаятов Акылбек.

Очень нужно помощь, не могу ни чего придумать, нужно срочно сдавать я ни как не получается,

помогите пожалуйста. Необходимо сделать в паскале В последовательности чисел p1,p2,......p20 вычислить сумму первых четырех положительных чисел,нужно сделать через массив но не пойму как
0 0
Перейти к ответам

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

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Тищенко Артём.
Держите
........................................

0 0
Отвечает Пешкова Татьяна.
Const
  n=20;
var
  p:array[1..n] of integer;
  i,k,s:integer;
begin
  Randomize;
  Writeln('Последовательность чисел');
  for i:=1 to n do
  begin
    p[i]:=Random(51)-25;
    Write(p[i],' ')
  end;
  Writeln;
  k:=0; s:=0; i:=1;
  repeat
    if p[i]>0 then begin s:=s+p[i]; Inc(k) end;
    Inc(i);
  until (k=4) or (i>n);
  Writeln('Сумма первых четырех положительных чисел равна ',s)
end.
   
Тестовое решение:
Последовательность чисел
-12 6 -21 5 -10 11 19 19 19 17 21 -4 -14 12 2 0 -20 10 17 -14
Сумма первых четырех положительных чисел равна 41




0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

Solving the Sum of First Four Positive Numbers in Pascal Using an Array

To solve the problem of calculating the sum of the first four positive numbers in a sequence using Pascal and an array, you can follow these steps:

1. Declare an Array: Start by declaring an array to store the sequence of numbers.

2. Initialize the Array: Initialize the array with the given sequence of numbers p1, p2, ......p20.

3. Calculate the Sum: Iterate through the array and calculate the sum of the first four positive numbers.

Here's a sample Pascal code to achieve this:

```pascal program SumOfFirstFourPositiveNumbers;

var p: array[1..20] of Integer; // Declare an array to store the sequence of numbers i, sum: Integer;

begin // Initialize the array with the given sequence of numbers p1, p2, ......p20 for i := 1 to 20 do begin // Initialize the array elements with the given values // For example: // p[i] := ; // Replace with the actual value of p1, p2, ......p20 end;

// Calculate the sum of the first four positive numbers sum := 0; for i := 1 to 4 do begin sum := sum + p[i]; end;

// Display the sum writeln('The sum of the first four positive numbers is: ', sum); end. ```

You can replace `` with the actual values of p1, p2, ......p20 in the code. This code declares an array, initializes it with the given sequence of numbers, calculates the sum of the first four positive numbers, and then displays the result.

I hope this helps! If you have any further questions or need additional assistance, feel free to ask.

0 0

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

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

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