提问几个简单的问题?

fashchina 2004-02-19 08:53:15
1.用三个文本框分别输入A,B,C,求一元二次方程ax^2+bx+c=0的实根.
2.求出一个3*3的二维数组的最大的植,并找出行号和列号.
3.运行时候,分别输入0-10的数字,如果输入负值,则结束输入.程序能去掉一个最高和最底分,在计算它的平均分数程序并显示出来.如果输入大于10的,程序必须能提出错误,并要求重新输入该数.
...全文
27 点赞 收藏 6
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
thelostland 2004-04-12
第三个问题的解来了
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
回复
thelostland 2004-04-12
第二个问题改一下:
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
回复
thelostland 2004-04-12

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
回复
leolan 2004-04-12
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
回复
thelostland 2004-04-12
问题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
回复
fashchina 2004-04-12
怎么没人回复?
回复
相关推荐
发帖
VB基础类
创建于2007-09-28

7491

社区成员

VB 基础类
申请成为版主
帖子事件
创建了帖子
2004-02-19 08:53
社区公告
暂无公告