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

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

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.
изи бризи



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.


Топ вопросов за вчера в категории Информатика
Последние заданные вопросы в категории Информатика
-
Математика
-
Литература
-
Алгебра
-
Русский язык
-
Геометрия
-
Английский язык
-
Химия
-
Физика
-
Биология
-
Другие предметы
-
История
-
Обществознание
-
Окружающий мир
-
География
-
Українська мова
-
Информатика
-
Українська література
-
Қазақ тiлi
-
Экономика
-
Музыка
-
Право
-
Беларуская мова
-
Французский язык
-
Немецкий язык
-
МХК
-
ОБЖ
-
Психология
-
Физкультура и спорт
-
Астрономия
-
Кыргыз тили
-
Оʻzbek tili