Vba дан динамический массив х(n). вывести элементы массива x, каждый из которых представляет собой квадрат элемента массива y, стоящий на нечетном месте.
Sub aaa() Rows.Clear Dim n As Integer, k As Integer, i As Integer n = CInt(InputBox("n=")) k = 2 * n - 1 ReDim y(1 To k) As Integer Randomize Timer For i = 1 To k y(i) = Int(Rnd * 100 - 50) Next i Dim ry As Range Set ry = Range(Cells(2, 2), Cells(2, k + 1)) ry = y ReDim x(1 To n) As Integer Dim rx As Range Set rx = Range(Cells(3, 2), Cells(3, n + 1)) For i = 1 To n x(i) = y(2 * i - 1) ^ 2 Next i rx = x Cells(2, 1) = "y" Cells(3, 1) = "x" Set ry = Range(Cells(2, 1), Cells(2, k + 1)) Set rx = Range(Cells(3, 1), Cells(3, n + 1)) End Sub
Rows.Clear
Dim n As Integer, k As Integer, i As Integer
n = CInt(InputBox("n="))
k = 2 * n - 1
ReDim y(1 To k) As Integer
Randomize Timer
For i = 1 To k
y(i) = Int(Rnd * 100 - 50)
Next i
Dim ry As Range
Set ry = Range(Cells(2, 2), Cells(2, k + 1))
ry = y
ReDim x(1 To n) As Integer
Dim rx As Range
Set rx = Range(Cells(3, 2), Cells(3, n + 1))
For i = 1 To n
x(i) = y(2 * i - 1) ^ 2
Next i
rx = x
Cells(2, 1) = "y"
Cells(3, 1) = "x"
Set ry = Range(Cells(2, 1), Cells(2, k + 1))
Set rx = Range(Cells(3, 1), Cells(3, n + 1))
End Sub