VB 程序设计题
答案:3 悬赏:0 手机版
解决时间 2021-02-03 03:51
- 提问者网友:星軌
- 2021-02-02 20:25
编写一个求三个数最大值的函数max(x,y,z),然后调用此函数求下列表达式的值,首先在文本框中输入a,b,c三个数,然后单击“计算”按钮,在文本框中输出表达式的值m。表达式为m=(max(a,b,c))/(max(a+b,b,c)Xmax(a,b,b+c))
最佳答案
- 五星知识达人网友:酒安江南
- 2021-02-02 20:50
Dim a As Integer
Dim b As Integer
Dim c As Integer
Private Sub Command1_Click()
Dim m As Single
m = (max(a, b, c)) / (max(a + b, b, c) * max(a, b, b + c))
Text1 = "m=" & Format(m, "0.0000")
End Sub
Private Sub Form_Load()
a = Val(InputBox("a="))
b = Val(InputBox("b="))
c = Val(InputBox("c="))
End Sub
Private Function max(ByVal x As Integer, ByVal y As Integer, ByVal z As Integer) As Integer
Dim t As Integer
If x > y Then t = x: x = y: y = t
If y > z Then t = y: y = z: z = t
If x > z Then t = x: x = z: z = t
max = z
End Function
Dim b As Integer
Dim c As Integer
Private Sub Command1_Click()
Dim m As Single
m = (max(a, b, c)) / (max(a + b, b, c) * max(a, b, b + c))
Text1 = "m=" & Format(m, "0.0000")
End Sub
Private Sub Form_Load()
a = Val(InputBox("a="))
b = Val(InputBox("b="))
c = Val(InputBox("c="))
End Sub
Private Function max(ByVal x As Integer, ByVal y As Integer, ByVal z As Integer) As Integer
Dim t As Integer
If x > y Then t = x: x = y: y = t
If y > z Then t = y: y = z: z = t
If x > z Then t = x: x = z: z = t
max = z
End Function
全部回答
- 1楼网友:渊鱼
- 2021-02-02 22:45
控件:
label1, label2, label3
text1, command1
代码:
private sub command1_click() ' command1单击事件
label3.caption = text1.text
end sub
private sub form_load() ' 程序装载事件
label1.alignment = 2 ' 居中显示
label1.caption = "欢迎学习" & vbcrlf & "visualbasic"
label3.borderstyle = 1
end sub
效果:
- 2楼网友:持酒劝斜阳
- 2021-02-02 21:36
Function max(x As Single, y As Single, z As Single) As Single
Dim m As Single
If x > y Then
m = x
Else
m = y
End If
If m < z Then m = z
max = m
End Function
Private Sub Command1_Click()
Dim sz As Variant, a As Single, b As Single, c As Single
sz = Split(Text1.Text, ",")
a = Val(sz(0))
b = Val(sz(1))
c = Val(sz(2))
m = max(a, b, c) / (max(a + b, b, c) * max(a, b, b + c))
Text1.Text = m
End Sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯