输入三角形。形的三条边a,b,c的值,根据其数值,判断能否构成三角若能则求出三角形的面积
答案:2 悬赏:20 手机版
解决时间 2021-07-31 14:36
- 提问者网友:姑娘长的好罪过
- 2021-07-31 08:44
vb作业,谢谢
最佳答案
- 五星知识达人网友:老鼠爱大米
- 2021-07-31 09:37
Private Sub Command1_Click()
Dim a As Double, b As Double, c As Double
a = CDbl(InputBox("请输入第一边的长度"))
b = CDbl(InputBox("请输入第二边的长度"))
c = CDbl(InputBox("请输入第三边的长度"))
If a + b < c Or a + c < b Or b + c < a Then
MsgBox "不能构成三角形"
Exit Sub
End If
MsgBox "三角形的面积是" & Format(area(a, b, c), ".00")
End Sub
Function area(a As Double, b As Double, c As Double)
Dim p As Double
p = (a + b + c) / 2
area = Sqr(p * (p - a) * (p - b) * (p - c))
End Function
Dim a As Double, b As Double, c As Double
a = CDbl(InputBox("请输入第一边的长度"))
b = CDbl(InputBox("请输入第二边的长度"))
c = CDbl(InputBox("请输入第三边的长度"))
If a + b < c Or a + c < b Or b + c < a Then
MsgBox "不能构成三角形"
Exit Sub
End If
MsgBox "三角形的面积是" & Format(area(a, b, c), ".00")
End Sub
Function area(a As Double, b As Double, c As Double)
Dim p As Double
p = (a + b + c) / 2
area = Sqr(p * (p - a) * (p - b) * (p - c))
End Function
全部回答
- 1楼网友:轻雾山林
- 2021-07-31 10:15
Option Explicit
Dim a As Single, b As Single, c As Single, p As Single, S As Single Private Sub Command1_Click() On Error GoTo e a = InputBox("a=") b = InputBox("b=") c = InputBox("c=") p = (a + b + c) / 2 If a < p And b < p And c < p Then S = Sqr(p * (p - a) * (p - b) * (p - c)) MsgBox S Else GoTo e End If Exit Sub e: MsgBox "不能构成三角形" End Sub
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯