Вопрос задан 26.08.2018 в 20:51. Предмет Информатика. Спрашивает Хайбуллов Даниэль.

Сформировать случайным образом массив из 25 целых чисел в промежутке [-10;10].Составить программу

удвоения чётных значений элементов и вывода массива в строку
0 0
Перейти к ответам

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

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Серикбаев Бегзат.
Var a:array[1..30] of integer;
n,i:integer;
begin
randomize;
for i:=1 to 25 do begin
a[i]:=random(-10,10);
write(a[i]:4);
end;
writeln();
for i:=1 to 25 do begin
if a[i] mod 2=0 then a[i]:=a[i]*2;
write(a[i]:4);
end;
end.
изи бризи
0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

Generating a Random Array of 25 Integers in the Range [-10, 10]

To generate a random array of 25 integers in the range [-10, 10], you can use the JavaScript programming language. Here's an example program that accomplishes this:

```javascript // Generate a random integer between min and max (inclusive) function getRandomInt(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; }

// Create an empty array to store the random numbers let array = [];

// Generate 25 random integers and add them to the array for (let i = 0; i < 25; i++) { let randomNumber = getRandomInt(-10, 10); array.push(randomNumber); }

// Print the array to the console console.log(array); ```

This program defines a function `getRandomInt` that generates a random integer between a given `min` and `max` value (inclusive). It then creates an empty array `array` and uses a loop to generate 25 random integers in the range [-10, 10] using the `getRandomInt` function. Finally, it prints the array to the console.

Doubling Even Values and Printing the Array

To double the even values in the array and print the resulting array, you can modify the previous program as follows:

```javascript // Generate a random integer between min and max (inclusive) function getRandomInt(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; }

// Create an empty array to store the random numbers let array = [];

// Generate 25 random integers and add them to the array for (let i = 0; i < 25; i++) { let randomNumber = getRandomInt(-10, 10); array.push(randomNumber); }

// Double the even values in the array for (let i = 0; i < array.length; i++) { if (array[i] % 2 === 0) { array[i] *= 2; } }

// Print the array to the console console.log(array); ```

In this modified program, after generating the random array, we iterate over each element in the array using a loop. If the element is even (i.e., divisible by 2), we double its value by multiplying it by 2. Finally, we print the modified array to the console.

Please note that this example uses JavaScript, but you can adapt the logic to other programming languages as well.

0 0

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

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

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