第三个问题的解来了
Private Sub Command3_Click()
Dim intTmp() As String
Dim strTmp As String
Dim i As Double, j As Integer
Dim Max As Double, Min As Double, MaxRow As Integer, MinRow As Integer
Dim Count As Double, Number As Integer
strTmp = ""
Do While 0 = 0
i = Val(InputBox("", "请输入0到10的数字"))
If i >= 0 Then
If i > 10 Then
MsgBox "请输入0到10的数字"
Else
strTmp = strTmp & i & ";"
End If
Else
If strTmp = "" Then
Exit Sub
Else
intTmp = Split(strTmp, ";")
Max = Val(intTmp(0))
Min = Val(intTmp(0))
MaxRow = 0
MinRow = 0
If UBound(intTmp) + 1 < 3 Then
MsgBox "请输入3个以上的数字"
Exit Sub
End If
For j = 1 To UBound(intTmp) - 1
If Max < Val(intTmp(j)) Then
Max = Val(intTmp(j))
MaxRow = j
End If
If Min > Val(intTmp(j)) Then
Min = Val(intTmp(j))
MinRow = j
End If
Next
Count = 0
Number = 0
Form1.Cls
For j = 0 To UBound(intTmp) - 1
If Not (j = MaxRow Or j = MinRow) Then
Form1.Print intTmp(j)
Count = Count + Val(intTmp(j))
Number = Number + 1
End If
Next
MsgBox "平均数为:" & Count / Number
Exit Sub
End If
End If
Loop
End Sub
第二个问题改一下:
Private Sub Command2_Click()
Dim i As Integer, j As Integer, Max As Integer, MaxRow As Integer, MaxCol As Integer
Dim intTmp(2, 2) As Integer
Form1.Cls
For i = 0 To 2
For j = 0 To 2
intTmp(i, j) = Int(Rnd(1) * 100)
Form1.Print intTmp(i, j)
Next
Next
Max = intTmp(0, 0)
MaxRow = 0
MaxCol = 0
For i = 0 To 2
For j = 0 To 2
If Max < intTmp(i, j) Then
Max = intTmp(i, j)
MaxRow = i
MaxCol = j
End If
Next
Next
MsgBox "最大值为:" & Max & "行号为:" & MaxRow & "列号为:" & MaxCol
End Sub
Private Sub Command1_Click()
Dim i As Double
Dim A As Integer, B As Integer, C As Integer
A = Int(Val(txtA.Text))
B = Int(Val(txtB.Text))
C = Int(Val(txtC.Text))
i = B ^ 2 - 4 * A * C
If i < 0 Then
MsgBox "无实根"
Exit Sub
Else
MsgBox A & "x^2+" & B & "x+" & C & "=0的解为:" & vbCrLf & "解1:" & ((-B + Sqr(i)) / 2 / A) & vbCrLf & "解2:" & ((-B - Sqr(i)) / 2 / A)
End If
End Sub
Private Sub Command2_Click()
Dim i As Integer, j As Integer, Max As Integer
Dim intTmp(2, 2) As Integer
Form1.Cls
For i = 0 To 2
For j = 0 To 2
intTmp(i, j) = Int(Rnd(1) * 100)
Form1.Print intTmp(i, j)
Next
Next
Max = intTmp(0, 0)
For i = 0 To 2
For j = 0 To 2
If Max < intTmp(i, j) Then
Max = intTmp(i, j)
End If
Next
Next
MsgBox Max
End Sub
2.
dim arrData(0 to 2,0 to 2) as long
dim i as integer,j as integer,iRow as integer,iCol as integer
dim lngMax as long
'//在這裡給arrData賦值
for i=0 to 2
for j=0 to 2
if arrData(i,j)>intMax then
lngMax=arrData(i,j)
iRow=i
iCol=j
end if
next
next
msgbox "行:" & iRow & vblf & "列:" & iCol & vblf & "最大值:" & lngMax
问题1的解:
Dim i As Double
Dim A As Integer, B As Integer, C As Integer
A = Int(Val(txtA.Text))
B = Int(Val(txtB.Text))
C = Int(Val(txtC.Text))
i = B ^ 2 - 4 * A * C
If i < 0 Then
MsgBox "无实根"
Exit Sub
Else
MsgBox A & "x^2+" & B & "x+" & C & "=0的解为:" & vbCrLf & "解1:" & ((-B + Sqr(i)) / 2 / A) & vbCrLf & "解2:" & ((-B - Sqr(i)) / 2 / A)
End If