Вопрос задан 05.05.2019 в 14:35. Предмет Информатика. Спрашивает Жанбырбек Шугыла.

Составьте программу, которая заполняет массив A[1..10] случайными целыми числами в диапазоне от -20

до 20, затем меняет местами первый элемент с максимальным элементом. Выведите на экран исходный и полученный массивы.
0 0
Перейти к ответам

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

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Голубков Илья.
Const
 n=10;
var
 a:array[1..n] of integer;
 i, MAX,t:integer;
begin
 randomize;
 writeln('Исходный массив:');
 for i:=1 to n do
  begin
   A[i]:=random(40)-20;
   writeln(a[i]);
  end;
 MAX:=-20-1;
 for i:=1 to n do
  if A[i]>MAX
   then
     MAX:=A[i];
 t:=A[1];         //Замена
 A[1]:=MAX;
 MAX:=t;
 Writeln('Готовый массив:');
 for i:=1 to n do
  writeln(A[i]);
end.
0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

Program to Fill and Swap Elements in an Array

Here is a program in Python that fills an array `A` with random integers in the range from -20 to 20 and then swaps the first element with the maximum element:

```python import random

# Function to fill the array with random integers def fill_array(arr): for i in range(len(arr)): arr[i] = random.randint(-20, 20)

# Function to swap the first element with the maximum element def swap_first_with_max(arr): max_index = arr.index(max(arr)) arr[0], arr[max_index] = arr[max_index], arr[0]

# Create an array of size 10 A = [0] * 10

# Fill the array with random integers fill_array(A)

# Swap the first element with the maximum element swap_first_with_max(A)

# Print the original and modified arrays print("Original Array:", A) print("Modified Array:", A) ```

This program uses the `random.randint()` function from the `random` module to generate random integers in the specified range. The `fill_array()` function fills the array `A` with random integers, and the `swap_first_with_max()` function swaps the first element with the maximum element in the array.

Please note that the program assumes you have Python installed on your system. If you don't have Python installed, you can download and install it from the official Python website.

Let me know if you need any further assistance!

0 0

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

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

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