产生n乘n的矩阵并输出 计算每一行的平均值VB
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/23 15:51:18
产生n乘n的矩阵并输出 计算每一行的平均值VB
产生n乘n的矩阵并输出 计算每一行的平均值VB
产生n乘n的矩阵并输出 计算每一行的平均值VB
Option Explicit
Private Sub Form_Load()
Me.Show
Me.AutoRedraw = True
Dim i As Integer, tem As String
Do
tem = InputBox("请输入要生成的n*n距型阵的n的个数 ", "请输入", 4)
Loop While Not IsNumeric(i)
i = CInt(tem)
Randomize
Dim arr() As Integer
ReDim arr(i ^ 2 - 1)
Dim x As Integer, y As Integer, h As Integer, ty As Integer
Print Tab(0); " |";
For x = 0 To i - 1
tem = IIf(x > 8, x + 1, "0" & x + 1)
Print Tab((x + 1) * 4); tem;
Next
Print Tab((x + 1) * 4); "|Average";
Print
ty = Me.CurrentY
For x = 0 To i - 1
Print Tab(1); CStr(IIf(x > 8, x + 1, "0" & x + 1) & "|");
For y = 0 To i - 1
arr(y * i + x) = Int(Rnd * 90) + 10
Print Tab((y + 1) * 4); CStr(arr(y * i + x));
h = h + arr(y * i + x)
Next
Print Tab((y + 1) * 4); "|" & h / i;
h = 0
Print
Next
Me.Line (0, ty)-(Me.ScaleWidth, ty)
End Sub