Sub abcd()
Dim a(1 To 10, 1 To 10) As Double
Dim n As Integer, m As Integer, i As Integer, j As Integer
Dim imx As Integer, jmx As Integer
Dim mx As Double
Range(Cells(1, 1), Cells(30, 20)).Clear
Do
n = CInt(InputBox("Введите размер матрицы от 2 до 10"))
Loop Until n >= 2 And n <= 10
Randomize Timer
Cells(1, 1) = "Исходная матрица"
For i = 1 To n
For j = 1 To n
a(i, j) = 18 * Rnd - 9
If i + j = 2 Then
mx = a(1, 1)
imx = 1
jmx = 1
Else
If Abs(a(i, j)) > Abs(mx) Then
mx = a(i, j)
imx = i
jmx = j
End If
Next j
Next i
Dim r As Range
Set r = Range(Cells(2, 1), Cells(1 + n, n))
r = a
r.NumberFormat = "0.00"
Dim cr As Integer
cr = n + 2
Cells(cr, 1) = "Максимальный по модулю элемент= " + Format(mx, "##0.00") + _
" в строке " + CStr(imx) + " в столбце " + CStr(jmx)
cr = cr + 1
m = n
If imx < m Then
For i = imx To m - 1
a(i, j) = a(i + 1, j)
m = m - 1
If jmx < n Then
For j = jmx To n - 1
For i = 1 To m
a(i, j) = a(i, j + 1)
n = n - 1
Cells(cr, 1) = "Удаление строки " + CStr(imx) + " и столбца " + CStr(jmx)
Set r = Range(Cells(cr + 1, 1), Cells(cr + n, n))
End Sub
Вывод будет или на лист, куда вставлен код (или где кнопка с кодом), или на текущий лист, если код сделать модулем проекта.
===== PascalABC.NET =====
function MinMax(a: array of integer): (integer, integer);
begin
var min := Abs(a[0]);
var max := min;
for var i := 1 to a.High do
if Abs(a[i]) < min then
min := Abs(a[i])
else if Abs(a[i]) > max then
max := Abs(a[i]);
Result := (min, max)
end;
var M := MatrRandom(5, 5, -50, 50);
M.Println(4);
var F := M.ElementsWithIndices
.Where(p -> p[2] >= p[1])
.Select(p -> p[0])
.ToArray;
F.Println;
var r := MinMax(F);
Println('Min=', r[0], ' max=', r[1])
end.
Sub abcd()
Dim a(1 To 10, 1 To 10) As Double
Dim n As Integer, m As Integer, i As Integer, j As Integer
Dim imx As Integer, jmx As Integer
Dim mx As Double
Range(Cells(1, 1), Cells(30, 20)).Clear
Do
n = CInt(InputBox("Введите размер матрицы от 2 до 10"))
Loop Until n >= 2 And n <= 10
Randomize Timer
Cells(1, 1) = "Исходная матрица"
For i = 1 To n
For j = 1 To n
a(i, j) = 18 * Rnd - 9
If i + j = 2 Then
mx = a(1, 1)
imx = 1
jmx = 1
Else
If Abs(a(i, j)) > Abs(mx) Then
mx = a(i, j)
imx = i
jmx = j
End If
End If
Next j
Next i
Dim r As Range
Set r = Range(Cells(2, 1), Cells(1 + n, n))
r = a
r.NumberFormat = "0.00"
Dim cr As Integer
cr = n + 2
Cells(cr, 1) = "Максимальный по модулю элемент= " + Format(mx, "##0.00") + _
" в строке " + CStr(imx) + " в столбце " + CStr(jmx)
cr = cr + 1
m = n
If imx < m Then
For i = imx To m - 1
For j = 1 To n
a(i, j) = a(i + 1, j)
Next j
Next i
End If
m = m - 1
If jmx < n Then
For j = jmx To n - 1
For i = 1 To m
a(i, j) = a(i, j + 1)
Next i
Next j
End If
n = n - 1
Cells(cr, 1) = "Удаление строки " + CStr(imx) + " и столбца " + CStr(jmx)
Set r = Range(Cells(cr + 1, 1), Cells(cr + n, n))
r = a
r.NumberFormat = "0.00"
End Sub
Вывод будет или на лист, куда вставлен код (или где кнопка с кодом), или на текущий лист, если код сделать модулем проекта.
===== PascalABC.NET =====
function MinMax(a: array of integer): (integer, integer);
begin
var min := Abs(a[0]);
var max := min;
for var i := 1 to a.High do
if Abs(a[i]) < min then
min := Abs(a[i])
else if Abs(a[i]) > max then
max := Abs(a[i]);
Result := (min, max)
end;
begin
var M := MatrRandom(5, 5, -50, 50);
M.Println(4);
var F := M.ElementsWithIndices
.Where(p -> p[2] >= p[1])
.Select(p -> p[0])
.ToArray;
F.Println;
var r := MinMax(F);
Println('Min=', r[0], ' max=', r[1])
end.