Вопрос задан 03.08.2018 в 06:58. Предмет Информатика. Спрашивает Игнаев Родион.

Заполнить массив случайными числами от 1 до 30. Заменить все элементы массива их удвоенными

значениями
0 0
Перейти к ответам

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

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Смирнова Елизавета.
Var i,n:integer;
a:array[1..1000] of integer;
begin
 write('Write size array: '); readln(n);

 for i:=1 to n do
  begin
   a[i]:=Random(30);
   write(a[i]:4,' ');
  end;
   writeln;
 for i:=1 to n do
  begin
   a[i]:=a[i]*2;
   write(a[i]:4,' ');
  end;
end.
0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

Для заполнения массива случайными числами от 1 до 30 и замены всех элементов массива их удвоенными значениями, вы можете использовать следующий код на языке JavaScript:

```javascript var arr = []; for (var i = 0; i < 10; i++) { arr[i] = Math.floor(Math.random() * 30) + 1; }

for (var i = 0; i < arr.length; i++) { arr[i] *= 2; } ```

В этом коде мы создаем пустой массив#### Filling an Array with Random Numbers and Doubling Their Values

To fill an array with random numbers from 1 to 30 and then replace all the elements with their doubled values, you can use the following JavaScript code:

```javascript // Create an array and fill it with random numbers from 1 to 30 var arr = []; for (var i = 0; i < 10; i++) { arr[i] = Math.floor(Math.random() * 30) + 1; }

// Double the values of all elements in the array for (var i = 0; i < arr.length; i++) { arr[i] *= 2; } ```

This code first creates an empty array and then fills it with 10 random numbers between 1 and 30. After that, it doubles the values of all the elements in the array.

This code uses the `Math.random()` function to generate random numbers and the `Math.floor()` function to round them down to the nearest integer. The `* 30` and `+ 1` are used to ensure that the random numbers fall within the range of 1 to 30.

This approach ensures that the array is filled with random numbers and then all the elements are replaced with their doubled values.

Let me know if you need further assistance!

0 0

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

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

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