procedure MatrA(var a: mass); var i, j: integer; begin for i := 1 to n do for j := 1 to m do begin writeln('a[', i, ',', j, ']: '); readln(a[i, j]) end end;
procedure MatrB(var b: mass); var i, j: integer; begin for i := 1 to n1 do for j := 1 to m1 do begin writeln('b[', i, ',', j, ']: '); readln(b[i, j]) end end;
procedure Sum(a, b: mass; var c: mass); var i, j: integer; begin for i := 1 to n do for j := 1 to m do c[i, j] := a[i, j] + b[i, j]; end;
begin writeln('Введите n,m матрицы A'); readln(n, m); MatrA(a); writeln('Введите n,m матрицы B'); readln(n1, m1); MatrB(b); if (n1 <> n) and (m1 <> m) then writeln('Матрицы сложить нельзя') else begin Sum(a, b, c); writeln('A+B'); for i := 1 to n do begin for j := 1 to m do write(c[i, j]:1:3, ' '); writeln end end; readln; end.
mass = array[1..10, 1..10] of real;
var
a, b, c: mass;
n, m, i, j, n1, m1: integer;
procedure MatrA(var a: mass);
var
i, j: integer;
begin
for i := 1 to n do
for j := 1 to m do
begin
writeln('a[', i, ',', j, ']: ');
readln(a[i, j])
end
end;
procedure MatrB(var b: mass);
var
i, j: integer;
begin
for i := 1 to n1 do
for j := 1 to m1 do
begin
writeln('b[', i, ',', j, ']: ');
readln(b[i, j])
end
end;
procedure Sum(a, b: mass; var c: mass);
var
i, j: integer;
begin
for i := 1 to n do
for j := 1 to m do
c[i, j] := a[i, j] + b[i, j];
end;
begin
writeln('Введите n,m матрицы A');
readln(n, m);
MatrA(a);
writeln('Введите n,m матрицы B');
readln(n1, m1);
MatrB(b);
if (n1 <> n) and (m1 <> m) then
writeln('Матрицы сложить нельзя')
else begin
Sum(a, b, c);
writeln('A+B');
for i := 1 to n do
begin
for j := 1 to m do
write(c[i, j]:1:3, ' ');
writeln
end
end;
readln;
end.
Программа:
Pascal:
№1)
var
arr: array[1..30] of integer;
i, pr: integer;
begin
// генерация массива из 30 рандомных чисел от -100 до 100
for i := 1 to 30 do arr[i] := random(-100, 100);
writeln(arr); // вывод массива
pr := 1;
for i := 1 to 30 do if (arr[i] mod 2 = 0) and (arr[i] mod 3 = 0) then pr := pr * arr[i];
pr.Print();
end.
№2)
var
arr: array[1..30] of integer;
i, s: integer;
begin
// генерация массива из 30 рандомных чисел от -1000 до 1000
for i := 1 to 30 do arr[i] := random(-1000, 1000);
writeln(arr); // вывод массива
s := 0;
for i := 1 to 30 do if (arr[i] >= 100) and (arr[i] < 1000) then begin
while arr[i] > 0 do begin
s := s + arr[i] mod 10;
arr[i] := arr[i] div 10;
end;
end;
s.print();
end.