Вопрос задан 17.06.2023 в 12:16. Предмет Информатика. Спрашивает Сербін Ваня.

Паскаль, не пойму почему не работает нашёл в интернете, в информатике не разбираюсь ,но должно

работать и прибавлять числа ,а он просто выводит два числа : program protect8;const N = 8;var i:integer; integer: array[0..8]of integer; begin for i:=0 to 8 do arr[i]:=random(1000); writeln(8); for i:=0 to 8 do arr[i]:=arr[i]+1; writeln(10); end.
0 0
Перейти к ответам

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

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

Ответ:

в коде бред какой-то... исправил...

Объяснение:

program protect8;

const N = 8;

var

 i:integer;

 arr: array[0..N]of integer;

begin

for i := 0 to N do

begin

 arr[i] := random(1000);

 write(arr[i], ', ');

end;

writeln;

for i := 0 to N do

begin

 arr[i] := arr[i] + 1;

 write(arr[i], ', ');

end;

end.


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

Pascal Code Issue: Adding Numbers

The Pascal code you provided has a few issues that prevent it from working as expected. Let's go through the code and identify the problems.

```pascal program protect8; const N = 8; var i: integer; arr: array[0..8] of integer; begin for i := 0 to 8 do arr[i] := random(1000); writeln(8); for i := 0 to 8 do arr[i] := arr[i] + 1; writeln(10); end. ```

Issue 1: Array Index Out of Bounds

The first issue is with the array declaration. In Pascal, arrays are zero-based, which means the index starts from 0, not 1. Therefore, the array declaration should be `array[0..7] of integer` instead of `array[0..8] of integer`. This will create an array with 8 elements, indexed from 0 to 7.

Issue 2: Incorrect Output Statements

The `writeln` statements in the code are not correctly displaying the array elements. Instead of printing the number of elements (8 and 10), you should use a loop to print the actual array elements.

Issue 3: Missing Output Statements

The code is missing output statements to display the modified array elements after adding 1 to each element. We need to add another loop to print the updated array elements.

Updated Pascal Code

Here's the updated Pascal code that addresses the issues mentioned above:

```pascal program protect8; const N = 8; var i: integer; arr: array[0..7] of integer; begin for i := 0 to 7 do arr[i] := random(1000); writeln('Original Array:'); for i := 0 to 7 do writeln(arr[i]); for i := 0 to 7 do arr[i] := arr[i] + 1; writeln('Updated Array:'); for i := 0 to 7 do writeln(arr[i]); end. ```

Explanation

The updated code initializes the array `arr` with random values between 0 and 999 using the `random` function. Then, it prints the original array elements using a loop. Next, it adds 1 to each element of the array using another loop. Finally, it prints the updated array elements.

Please try running the updated code, and it should correctly display the original array and the updated array with each element incremented by 1.

Let me know if you have any further questions!

0 0

Похожие вопросы

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

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

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