
Заполнить двухмерный массив размера N*M случайными целыми числами, диапазон изменения которых
вводится с клавиатуры. Вывести массив на экран. Заполнить одномерный массив, элементами которого является сумма элементов каждой строки двухмерного массива. Вывести его на экран(Тоже задание сделать и для столбцов).

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

nn = 50;
nm = 50;
var
Mas: array[1..nn, 1..nm] of integer;
R: array[1..nn] of integer;
C: array[1..nm] of integer;
i, j, n, m, k, s, a, b, p : integer;
begin
Write('Введите число строк и столбцов матрицы: '); Readln(n,m);
Write('Введите границы для элементов массива: '); Readln(a,b);
{ защита от злобных буратинок }
if a>b then begin k:=a; a:=b; b:=k end;
{ найдем количество позиций, требуемое для вывода элементов }
k:=(b-a+1);
if k=0 then p:=2
else begin
if k<0 then begin p:=4; k:=-k end
else p:=3;
p:=p+trunc(ln(k)/ln(10))
end;
{ заполнение массива случайными числами }
Randomize;
Writeln('Исходная матрица');
for i := 1 to n do
begin
for j := 1 to m do
begin
Mas[i, j] := Random(b-a+1) + a;
Write(Mas[i, j]:p)
end;
Writeln
end;
{ суммы по строкам }
Writeln('Суммы элементов по строкам');
for i:=1 to n do
begin
s:=0;
for j:=1 to m do s:=s+Mas[i,j];
R[i]:=s;
Writeln(s:p+1)
end;
{ суммы по столбцам }
Writeln('Суммы элементов по столбцам');
for j:=1 to m do
begin
s:=0;
for i:=1 to n do s:=s+Mas[i,j];
C[j]:=s;
Write(s:p+1)
end;
Writeln
end.
Тестовое решение:
Введите число строк и столбцов матрицы: 6 9
Введите границы для элементов массива: -50 200
Исходная матрица
94 -48 2 83 -49 125 18 110 15
168 51 57 196 18 132 -36 -25 56
95 55 1 20 -50 -27 174 -11 -27
109 142 155 -34 188 160 175 -46 196
27 85 156 103 -50 13 64 36 -14
122 116 -2 42 173 177 22 145 67
Суммы элементов по строкам
350
617
230
1045
420
862
Суммы элементов по столбцам
615 401 369 410 230 580 417 209 293



Task Description
You need to fill a two-dimensional array of size N*M with random integers. The range of these integers will be inputted from the keyboard. Then, you need to display the array on the screen. After that, you need to fill a one-dimensional array with the sum of the elements of each row of the two-dimensional array. Finally, you need to display the one-dimensional array on the screen. The same task should be done for the columns as well.Solution
To solve this task, we can follow these steps:1. Read the values of N and M from the user. 2. Read the range of the random integers from the user. 3. Create a two-dimensional array of size N*M. 4. Fill the two-dimensional array with random integers within the specified range. 5. Display the two-dimensional array on the screen. 6. Create a one-dimensional array of size N to store the sum of each row. 7. Calculate the sum of each row and store it in the one-dimensional array. 8. Display the one-dimensional array on the screen. 9. Repeat steps 6-8 for the columns.
Here's the code that implements the solution in Python:
```python import random
# Step 1: Read the values of N and M from the user N = int(input("Enter the number of rows (N): ")) M = int(input("Enter the number of columns (M): "))
# Step 2: Read the range of the random integers from the user min_range = int(input("Enter the minimum value for the random integers: ")) max_range = int(input("Enter the maximum value for the random integers: "))
# Step 3: Create a two-dimensional array of size N*M array = [[0] * M for _ in range(N)]
# Step 4: Fill the two-dimensional array with random integers within the specified range for i in range(N): for j in range(M): array[i][j] = random.randint(min_range, max_range)
# Step 5: Display the two-dimensional array on the screen print("Two-dimensional array:") for row in array: print(row)
# Step 6: Create a one-dimensional array of size N to store the sum of each row row_sums = [0] * N
# Step 7: Calculate the sum of each row and store it in the one-dimensional array for i in range(N): row_sums[i] = sum(array[i])
# Step 8: Display the one-dimensional array on the screen print("Row sums:") print(row_sums)
# Step 9: Repeat steps 6-8 for the columns column_sums = [0] * M for j in range(M): column_sums[j] = sum(array[i][j] for i in range(N))
print("Column sums:") print(column_sums) ```
This code will prompt the user to enter the number of rows (N) and columns (M), as well as the range of the random integers. It will then generate a two-dimensional array filled with random integers within the specified range. After that, it will display the two-dimensional array on the screen. It will also calculate and display the sum of each row and column in separate one-dimensional arrays.
Please note that the code provided is in Python. If you need the code in a different programming language, please let me know.


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