用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
哪儿错了啊,怎么老显示是正三角形啊 展开
展开全部
首先,你的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
展开全部
'示例代码如下:
private
sub
form_click()
a
=
val(inputbox("请输入三角形的一条边:"))
b
=
val(inputbox("请输入三角形的一条边:"))
c
=
val(inputbox("请输入三角形的一条边:"))
if
a
+
b
>
c
and
a
+
c
>
b
and
b
+
c
>
a
then
if
a
=
b
and
b
=
c
then
msgbox
"这是一个等边三角形"
elseif
(a
=
b
and
b
<>
c)
or
(b
=
c
and
a
<>
c)
or
(c
=
a
and
a
<>
b)
then
msgbox
"这是一个等腰三角形"
elseif
a
^
2
+
b
^
2
=
c
^
2
or
a
^
2
+
c
^
2
=
b
^
2
or
b
^
2
+
c
^
2
=
a
^
2
then
msgbox
"这是一个直角三角形"
else
msgbox
"这是一个普通三角形"
end
if
else
msgbox
"不能组成三角形"
end
if
end
sub
private
sub
form_click()
a
=
val(inputbox("请输入三角形的一条边:"))
b
=
val(inputbox("请输入三角形的一条边:"))
c
=
val(inputbox("请输入三角形的一条边:"))
if
a
+
b
>
c
and
a
+
c
>
b
and
b
+
c
>
a
then
if
a
=
b
and
b
=
c
then
msgbox
"这是一个等边三角形"
elseif
(a
=
b
and
b
<>
c)
or
(b
=
c
and
a
<>
c)
or
(c
=
a
and
a
<>
b)
then
msgbox
"这是一个等腰三角形"
elseif
a
^
2
+
b
^
2
=
c
^
2
or
a
^
2
+
c
^
2
=
b
^
2
or
b
^
2
+
c
^
2
=
a
^
2
then
msgbox
"这是一个直角三角形"
else
msgbox
"这是一个普通三角形"
end
if
else
msgbox
"不能组成三角形"
end
if
end
sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
a = Val(InputBox("请输入第一条边的长度", "输入窗口"))
b = Val(InputBox("请输入第二条边的长度", "输入窗口"))
c = Val(InputBox("请输入第三条边的长度", "输入窗口"))
If a + b > c And b + c > a And a + c > b Then
If a = b And b = c And a = c Then
Print "等边三角形"
ElseIf a = b And a ^ 2 + b ^ 2 = c ^ 2 Or b = c And b ^ 2 + c ^ 2 = a ^ 2 Or a = c And a ^ 2 + c ^ 2 = b ^ 2 Then
Print "等腰直角三角形"
ElseIf a = b Or b = c Or a = c Then
Print "等腰三角形"
ElseIf a ^ 2 + b ^ 2 = c ^ 2 Or b ^ 2 + c ^ 2 = a ^ 2 Or a ^ 2 + c ^ 2 = b ^ 2 Then
Print "直角三角形"
Else
Print "普通三角形"
End If
Else
Print "不是三角形"
End If
End Sub
a = Val(InputBox("请输入第一条边的长度", "输入窗口"))
b = Val(InputBox("请输入第二条边的长度", "输入窗口"))
c = Val(InputBox("请输入第三条边的长度", "输入窗口"))
If a + b > c And b + c > a And a + c > b Then
If a = b And b = c And a = c Then
Print "等边三角形"
ElseIf a = b And a ^ 2 + b ^ 2 = c ^ 2 Or b = c And b ^ 2 + c ^ 2 = a ^ 2 Or a = c And a ^ 2 + c ^ 2 = b ^ 2 Then
Print "等腰直角三角形"
ElseIf a = b Or b = c Or a = c Then
Print "等腰三角形"
ElseIf a ^ 2 + b ^ 2 = c ^ 2 Or b ^ 2 + c ^ 2 = a ^ 2 Or a ^ 2 + c ^ 2 = b ^ 2 Then
Print "直角三角形"
Else
Print "普通三角形"
End If
Else
Print "不是三角形"
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你的Dim a As Single, b As Single, c As Single 在过程中.
每次进来.这3个值都是0..所以是相等的
每次进来.这3个值都是0..所以是相等的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
a,b,c没有贼值,都初始化成0,因此老显示是正三角形
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询