vb编程代码 输入三角形的三条边,判断它们是否构成三角形的3个边,要求输出的三条边及判断结果。
如果能够成一个三角形,则计算三角形的面积并用msgbox函数进行输出面积area=sqr(s*(s-a)*(s-b)*(s-c))其中s=(a+b+c)/2)...
如果能够成一个三角形,则计算三角形的面积并用msgbox函数进行输出
面积area=sqr(s*(s-a)*(s-b)*(s-c))其中s=(a+b+c)/2) 展开
面积area=sqr(s*(s-a)*(s-b)*(s-c))其中s=(a+b+c)/2) 展开
展开全部
单击Command1即可。代码如下。
==============================
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
==============================
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
展开全部
sub command1_click()
dim a,b,c as double
a=inputbox("输入第一个边长:")
b=inputbox("输入第二个边长:")
c=inputbox("输入第三个边长:")
'在这里最好加上对输入的值进行一个判断,判断输入的是否为数字.
if panduan(a,b,c) then
s=(a+b+c)/2)
msgbox "三角行的三边长分别是:" & a & ", " & b & ", " & c & "." & vbcrlf & "面积是:" & sqr(s*(s-a)*(s-b)*(s-c))
else
msgbox "边长为" & a & ", " & b & "," & c & "不能构成三角形"
endif
end sub
function panduan(byval a as double,b as double,c as double) as boolean
panduan=a+b>c
end function
dim a,b,c as double
a=inputbox("输入第一个边长:")
b=inputbox("输入第二个边长:")
c=inputbox("输入第三个边长:")
'在这里最好加上对输入的值进行一个判断,判断输入的是否为数字.
if panduan(a,b,c) then
s=(a+b+c)/2)
msgbox "三角行的三边长分别是:" & a & ", " & b & ", " & c & "." & vbcrlf & "面积是:" & sqr(s*(s-a)*(s-b)*(s-c))
else
msgbox "边长为" & a & ", " & b & "," & c & "不能构成三角形"
endif
end sub
function panduan(byval a as double,b as double,c as double) as boolean
panduan=a+b>c
end function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询