VB编程 输入三角形三条边长啊,a,b,c的值,根据其数值,判断是否构成三角形。
4个回答
展开全部
a = Val(inputbox("输入a"))
b = Val(inputbox("输入b"))
c = Val(inputbox("输入c"))
If a+b > c And b+c>a And c+a>b Then
'能构成
If a=b And b=c Then
Msgbox "等边三角形"
ElseIf a=b Or b=c Or a=c Then
Msgbox "等腰三角形"
ElseIf a^2 + b^2 = c^2 Or a^2 + c^2 = b^2 Or c^2 + b^2 = a^2 Then
Msgbox "一般三角形"
end if
Else
Msgbox "不能构成三角形"
end if
b = Val(inputbox("输入b"))
c = Val(inputbox("输入c"))
If a+b > c And b+c>a And c+a>b Then
'能构成
If a=b And b=c Then
Msgbox "等边三角形"
ElseIf a=b Or b=c Or a=c Then
Msgbox "等腰三角形"
ElseIf a^2 + b^2 = c^2 Or a^2 + c^2 = b^2 Or c^2 + b^2 = a^2 Then
Msgbox "一般三角形"
end if
Else
Msgbox "不能构成三角形"
end if
更多追问追答
追问
不行啊 不能判断等腰跟直角 都是显示不能构成三角形
追答
漏了一个
a = Val(InputBox("输入a"))
b = Val(InputBox("输入b"))
c = Val(InputBox("输入c"))
If a + b > c And b + c > a And c + a > b Then
'能构成
If a = b And b = c Then
MsgBox "等边三角形"
ElseIf a = b Or b = c Or a = c Then
MsgBox "等腰三角形"
ElseIf a ^ 2 + b ^ 2 = c ^ 2 Or a ^ 2 + c ^ 2 = b ^ 2 Or c ^ 2 + b ^ 2 = a ^ 2 Then
MsgBox "直角三角形"
Else
MsgBox "一般三角形"
End If
Else
MsgBox "不能构成三角形"
End If
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Option Explicit
Private Sub Form_Load()
MsgBox GetShape(3, 4, 5)
End Sub
Function GetShape(a As Integer, b As Integer, c As Integer) As String
Dim s As String
Dim t(2) As Integer
t(0) = a
t(1) = b
t(2) = c
mp t
If t(0) + t(1) > t(2) Then
If t(0) = t(1) And t(1) = t(2) Then
s = "等边三角形"
ElseIf (t(0) = t(1) Or t(2) = t(1)) And t(2) <> t(0) Then
s = "等腰三角形"
If t(0) ^ 2 + t(1) ^ 2 = t(2) ^ 2 Then s = ",等腰直角三角形"
ElseIf t(0) ^ 2 + t(1) ^ 2 = t(2) ^ 2 Then
s = "直角三角形"
Else
s = "一般三角形"
End If
Else
s = "不能成三角形"
End If
GetShape = s
End Function
Sub mp(a() As Integer, Optional index As Integer = 0)
Dim t As Integer
If UBound(a) > index Then
If a(index) > a(index + 1) Then
t = a(index)
a(index) = a(index + 1)
a(index + 1) = t
End If
mp a, index + 1
End If
End Sub
Private Sub Form_Load()
MsgBox GetShape(3, 4, 5)
End Sub
Function GetShape(a As Integer, b As Integer, c As Integer) As String
Dim s As String
Dim t(2) As Integer
t(0) = a
t(1) = b
t(2) = c
mp t
If t(0) + t(1) > t(2) Then
If t(0) = t(1) And t(1) = t(2) Then
s = "等边三角形"
ElseIf (t(0) = t(1) Or t(2) = t(1)) And t(2) <> t(0) Then
s = "等腰三角形"
If t(0) ^ 2 + t(1) ^ 2 = t(2) ^ 2 Then s = ",等腰直角三角形"
ElseIf t(0) ^ 2 + t(1) ^ 2 = t(2) ^ 2 Then
s = "直角三角形"
Else
s = "一般三角形"
End If
Else
s = "不能成三角形"
End If
GetShape = s
End Function
Sub mp(a() As Integer, Optional index As Integer = 0)
Dim t As Integer
If UBound(a) > index Then
If a(index) > a(index + 1) Then
t = a(index)
a(index) = a(index + 1)
a(index + 1) = t
End If
mp a, index + 1
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Function Check_3(a As Double, b As Double, c As Double) As String
If a + b <= c Or a + c <= b Or b + c <= a Then Check_3 = "不构成三角形"
If a = 0 Or b = 0 Or c = 0 Then Check_3 = "不构成三角形"
If a = b Or a = c Or b = c Then Check_3 = "等腰三角形"
If a = b And a = c Then Check_3 = "等边三角形"
a2 = Round(a ^ 2, 0)
b2 = Round(b ^ 2, 0)
c2 = Round(c ^ 2, 0)
If a2 = b2 + c2 Or b2 = a2 + c2 Or c2 = a2 + b2 Then Check_3 = Check_3 & "直角三角形"
End Function
Private Sub Command1_Click()
MsgBox Check_3(1, 1, Sqr(2))
End Sub
If a + b <= c Or a + c <= b Or b + c <= a Then Check_3 = "不构成三角形"
If a = 0 Or b = 0 Or c = 0 Then Check_3 = "不构成三角形"
If a = b Or a = c Or b = c Then Check_3 = "等腰三角形"
If a = b And a = c Then Check_3 = "等边三角形"
a2 = Round(a ^ 2, 0)
b2 = Round(b ^ 2, 0)
c2 = Round(c ^ 2, 0)
If a2 = b2 + c2 Or b2 = a2 + c2 Or c2 = a2 + b2 Then Check_3 = Check_3 & "直角三角形"
End Function
Private Sub Command1_Click()
MsgBox Check_3(1, 1, Sqr(2))
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
if a+b>c and a+c>b and b+c>a then
if a=b and b=c then
'等边三角形
elseif a=b or b=c or a=c then
'等腰三角形
elseif a^2+b^2=c^2 or a^2 +c^2=b^2 or b^2+c^2=a^2 then
'直角三角形
else
'其他三角形
end if
else
'不是三角形
end if
if a=b and b=c then
'等边三角形
elseif a=b or b=c or a=c then
'等腰三角形
elseif a^2+b^2=c^2 or a^2 +c^2=b^2 or b^2+c^2=a^2 then
'直角三角形
else
'其他三角形
end if
else
'不是三角形
end if
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询