> 其他 >
用VB编程,根据输入的3个边长值计算三角形的面积,如果输入值不符合“任意两边之和大于第三边”提示错误
人气:297 ℃ 时间:2020-04-23 09:36:10
解答
Public Function Area(a As Double, b As Double, c As Double) As Double
If a + b < c Or a + c < b Or b + c < a Then
MSGBOX "要求任意两边之和大于第三边"
Exit Function
endif
Dim s As Double
s = 0.5 * (a + b + c)
a = s - a
b = s - b
c = s - c
Area = Sqr(s * a * b * c)
End Function
Private Sub Command1_Click()
Me.Caption = Area(3, 4, 5)
End Sub
推荐
猜你喜欢
© 2026 79432.Com All Rights Reserved.
电脑版|手机版