在vb中判断一个三角形属于什么类型啊
PrivateSubCommand1_Click()DimaAsSingle,bAsSingle,cAsSingleIfa=bAndb=cThenLabel2.Capti...
Private Sub Command1_Click()
Dim a As Single, b As Single, c As Single
If a = b And b = c Then
Label2.Caption = "此三角形是正三角形"
ElseIf a = b <> c And a ^ 2 + b ^ 2 = c ^ 2 Then
Label2.Caption = "此三角形是等腰直角三角形"
ElseIf a = c <> b And a ^ 2 + b ^ 2 = c ^ 2 Then
Label2.Caption = "此三角形是等腰直角三角形"
ElseIf b = c <> a And a ^ 2 + b ^ 2 = c ^ 2 Then
Label2.Caption = "此三角形是等腰直角三角形"
ElseIf a = b <> c Then
Label2.Caption = "此三角形是等腰三角形"
ElseIf a = c <> b Then
Label2.Caption = "此三角形是等腰三角形"
ElseIf c = b <> a Then
Label2.Caption = "此三角形是等腰三角形"
ElseIf a ^ 2 + b ^ 2 = c ^ 2 Then
Label2.Caption = "此三角形是直角三角形"
Else
Label2.Caption = "此三角形是一般三角形"
End If
End Sub
我这段代码哪错了啊,为什么老显示一个结果就是正三角形啊,哪位很懂的人给点提示吧。请尽快啊。不胜感激啊 展开
Dim a As Single, b As Single, c As Single
If a = b And b = c Then
Label2.Caption = "此三角形是正三角形"
ElseIf a = b <> c And a ^ 2 + b ^ 2 = c ^ 2 Then
Label2.Caption = "此三角形是等腰直角三角形"
ElseIf a = c <> b And a ^ 2 + b ^ 2 = c ^ 2 Then
Label2.Caption = "此三角形是等腰直角三角形"
ElseIf b = c <> a And a ^ 2 + b ^ 2 = c ^ 2 Then
Label2.Caption = "此三角形是等腰直角三角形"
ElseIf a = b <> c Then
Label2.Caption = "此三角形是等腰三角形"
ElseIf a = c <> b Then
Label2.Caption = "此三角形是等腰三角形"
ElseIf c = b <> a Then
Label2.Caption = "此三角形是等腰三角形"
ElseIf a ^ 2 + b ^ 2 = c ^ 2 Then
Label2.Caption = "此三角形是直角三角形"
Else
Label2.Caption = "此三角形是一般三角形"
End If
End Sub
我这段代码哪错了啊,为什么老显示一个结果就是正三角形啊,哪位很懂的人给点提示吧。请尽快啊。不胜感激啊 展开
4个回答
展开全部
修改下:
If a = b And b = c Then
Label2.Caption = "此三角形是正三角形"
ElseIf a = b And b <> c And a ^ 2 + b ^ 2 = c ^ 2 Then
Label2.Caption = "此三角形是等腰直角三角形"
ElseIf a = c And c <> b And a ^ 2 + b ^ 2 = c ^ 2 Then
Label2.Caption = "此三角形是等腰直角三角形"
ElseIf b = c And c <> a And a ^ 2 + b ^ 2 = c ^ 2 Then
Label2.Caption = "此三角形是等腰直角三角形"
ElseIf a = b And b <> c Then
Label2.Caption = "此三角形是等腰三角形"
ElseIf a = c And c <> b Then
Label2.Caption = "此三角形是等腰三角形"
ElseIf c = b And b <> a Then
Label2.Caption = "此三角形是等腰三角形"
ElseIf a ^ 2 + b ^ 2 = c ^ 2 Then
Label2.Caption = "此三角形是直角三角形"
Else
Label2.Caption = "此三角形是一般三角形"
End If
If a = b And b = c Then
Label2.Caption = "此三角形是正三角形"
ElseIf a = b And b <> c And a ^ 2 + b ^ 2 = c ^ 2 Then
Label2.Caption = "此三角形是等腰直角三角形"
ElseIf a = c And c <> b And a ^ 2 + b ^ 2 = c ^ 2 Then
Label2.Caption = "此三角形是等腰直角三角形"
ElseIf b = c And c <> a And a ^ 2 + b ^ 2 = c ^ 2 Then
Label2.Caption = "此三角形是等腰直角三角形"
ElseIf a = b And b <> c Then
Label2.Caption = "此三角形是等腰三角形"
ElseIf a = c And c <> b Then
Label2.Caption = "此三角形是等腰三角形"
ElseIf c = b And b <> a Then
Label2.Caption = "此三角形是等腰三角形"
ElseIf a ^ 2 + b ^ 2 = c ^ 2 Then
Label2.Caption = "此三角形是直角三角形"
Else
Label2.Caption = "此三角形是一般三角形"
End If
展开全部
Private Sub Command1_Click()
Dim a As Single, b As Single, c As Single
a = Val(InputBox("a = ", "请输入边长"))
b = Val(InputBox("b = ", "请输入边长"))
c = Val(InputBox("c = ", "请输入边长"))
Select Case True
Case a = 0 Or b = 0 Or c = 0
Label2.Caption = "此三角形是不存在,边长为0"
Case a + b <= c Or b + c <= a Or c + a <= b
Label2.Caption = "此三角形是不存在,无法构成"
Case a = b And b = c
Label2.Caption = "此三角形是正三角形"
Case (a ^ 2 + b ^ 2 = c ^ 2 And a = b And a <> c) Or (b ^ 2 + c ^ 2 = a ^ 2 And b = c And b <> a) Or (c ^ 2 + a ^ 2 = b ^ 2 And c = a And c <> b)
Label2.Caption = "此三角形是等腰直角三角形"
Case (a = b And a <> c) Or (b = c And b <> a) Or (c = a And c <> b)
Label2.Caption = "此三角形是等腰三角形"
Case (a <> b And a <> c And b <> c) And (a ^ 2 + b ^ 2 = c ^ 2) Or (b ^ 2 + c ^ 2 = a ^ 2) Or (c ^ 2 + a ^ 2 = b ^ 2)
Label2.Caption = "此三角形是直角三角形"
Case Else
Label2.Caption = "此三角形是一般三角形"
End Select
End Sub
根据 niuxiaojia45 的,修改了一下,加了两个判断,一个是边长为0,一个是两边长的和小于或等于第三边长。
Dim a As Single, b As Single, c As Single
a = Val(InputBox("a = ", "请输入边长"))
b = Val(InputBox("b = ", "请输入边长"))
c = Val(InputBox("c = ", "请输入边长"))
Select Case True
Case a = 0 Or b = 0 Or c = 0
Label2.Caption = "此三角形是不存在,边长为0"
Case a + b <= c Or b + c <= a Or c + a <= b
Label2.Caption = "此三角形是不存在,无法构成"
Case a = b And b = c
Label2.Caption = "此三角形是正三角形"
Case (a ^ 2 + b ^ 2 = c ^ 2 And a = b And a <> c) Or (b ^ 2 + c ^ 2 = a ^ 2 And b = c And b <> a) Or (c ^ 2 + a ^ 2 = b ^ 2 And c = a And c <> b)
Label2.Caption = "此三角形是等腰直角三角形"
Case (a = b And a <> c) Or (b = c And b <> a) Or (c = a And c <> b)
Label2.Caption = "此三角形是等腰三角形"
Case (a <> b And a <> c And b <> c) And (a ^ 2 + b ^ 2 = c ^ 2) Or (b ^ 2 + c ^ 2 = a ^ 2) Or (c ^ 2 + a ^ 2 = b ^ 2)
Label2.Caption = "此三角形是直角三角形"
Case Else
Label2.Caption = "此三角形是一般三角形"
End Select
End Sub
根据 niuxiaojia45 的,修改了一下,加了两个判断,一个是边长为0,一个是两边长的和小于或等于第三边长。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
private
sub
command1_click()
dim
a,
b,
c
as
single
dim
s
as
single,
area
as
single
a
=
val(inputbox("请输入三角形边长a"))
b
=
val(inputbox("请输入三角形边长b"))
c
=
val(inputbox("请输入三角形边长c"))
if
a
+
b
>
c
and
b
+
c
>
a
and
a
+
c
>
b
then
print
"能够成三角形"
s
=
(a
+
b
+
c)
/
2
area
=
sqr(s
*
(s
-
a)
*
(s
-
c)
*
(s
-
b))
print
"面积为:";
area
else
print
"不能够成三角形"
end
if
end
sub
sub
command1_click()
dim
a,
b,
c
as
single
dim
s
as
single,
area
as
single
a
=
val(inputbox("请输入三角形边长a"))
b
=
val(inputbox("请输入三角形边长b"))
c
=
val(inputbox("请输入三角形边长c"))
if
a
+
b
>
c
and
b
+
c
>
a
and
a
+
c
>
b
then
"能够成三角形"
s
=
(a
+
b
+
c)
/
2
area
=
sqr(s
*
(s
-
a)
*
(s
-
c)
*
(s
-
b))
"面积为:";
area
else
"不能够成三角形"
end
if
end
sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
首先,你的a,b,c的值都没有输入,怎么判断呢!再有就是你的判断条件上有一点乱。我把你的代码稍改了点。你看一下:
Private Sub Command1_Click()
Dim a As Single, b As Single, c As Single
a = Val(InputBox("请输入第一条边"))
b = Val(InputBox("请输入第二条边"))
c = Val(InputBox("请输入第三条边"))
If a < b + c And b < a + c And c < a + b Then
If a = b And b = c Then
Label2.Caption = "此三角形是正三角形"
ElseIf (a = b And a <> c And a ^ 2 + b ^ 2 = c ^ 2) Or (a = c And a <> b And a ^ 2 + b ^ 2 = c ^ 2) Or (b = c And b <> a And a ^ 2 + b ^ 2 = c ^ 2) Then
Label2.Caption = "此三角形是等腰直角三角形"
ElseIf (a = b And a <> c) Or (a = c And a <> b) Or (c = b And c <> a) Then
Label2.Caption = "此三角形是等腰三角形"
ElseIf (a ^ 2 + b ^ 2 = c ^ 2) Or (a ^ 2 + c ^ 2 = b ^ 2) Or (b ^ 2 + c ^ 2 = a ^ 2) Then
Label2.Caption = "此三角形是直角三角形"
Else
Label2.Caption = "此三角形是一般三角形"
End If
Else
MsgBox "输入的三条边不能组成三角形!", vbOKOnly + vbCritical, "提示 "
End If
End Sub
Private Sub Command1_Click()
Dim a As Single, b As Single, c As Single
a = Val(InputBox("请输入第一条边"))
b = Val(InputBox("请输入第二条边"))
c = Val(InputBox("请输入第三条边"))
If a < b + c And b < a + c And c < a + b Then
If a = b And b = c Then
Label2.Caption = "此三角形是正三角形"
ElseIf (a = b And a <> c And a ^ 2 + b ^ 2 = c ^ 2) Or (a = c And a <> b And a ^ 2 + b ^ 2 = c ^ 2) Or (b = c And b <> a And a ^ 2 + b ^ 2 = c ^ 2) Then
Label2.Caption = "此三角形是等腰直角三角形"
ElseIf (a = b And a <> c) Or (a = c And a <> b) Or (c = b And c <> a) Then
Label2.Caption = "此三角形是等腰三角形"
ElseIf (a ^ 2 + b ^ 2 = c ^ 2) Or (a ^ 2 + c ^ 2 = b ^ 2) Or (b ^ 2 + c ^ 2 = a ^ 2) Then
Label2.Caption = "此三角形是直角三角形"
Else
Label2.Caption = "此三角形是一般三角形"
End If
Else
MsgBox "输入的三条边不能组成三角形!", vbOKOnly + vbCritical, "提示 "
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询