在vb中如何y用if方法做判断三角形形状的程序 45
1个回答
展开全部
Private Sub Command1_Click()
Dim a As Double
Dim b As Double
Dim c As Double
Dim s As String
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 Or a = c Or b = c Then '等腰
If a ^ 2 + b ^ 2 = c ^ 2 Or a ^ 2 + c ^ 2 = b ^ 2 Or b ^ 2 + c ^ 2 = a ^ 2 Then
s = "等腰直角三角形"
ElseIf a = b And a = c Then
s = "等边三角形"
Else
s = "等腰三角形"
End If
ElseIf a ^ 2 + b ^ 2 = c ^ 2 Or a ^ 2 + c ^ 2 = b ^ 2 Or b ^ 2 + c ^ 2 = a ^ 2 Then
s = "直角三角形"
Else
s = "任意三角形"
End If
Else
s = "不能构成三角形!"
End If
s = a & "," & b & "," & c & "这三条边构成的图形为:" & s
Me.List1.AddItem s
End Sub
Private Sub Command2_Click()
Me.List1.Clear
End Sub
Dim a As Double
Dim b As Double
Dim c As Double
Dim s As String
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 Or a = c Or b = c Then '等腰
If a ^ 2 + b ^ 2 = c ^ 2 Or a ^ 2 + c ^ 2 = b ^ 2 Or b ^ 2 + c ^ 2 = a ^ 2 Then
s = "等腰直角三角形"
ElseIf a = b And a = c Then
s = "等边三角形"
Else
s = "等腰三角形"
End If
ElseIf a ^ 2 + b ^ 2 = c ^ 2 Or a ^ 2 + c ^ 2 = b ^ 2 Or b ^ 2 + c ^ 2 = a ^ 2 Then
s = "直角三角形"
Else
s = "任意三角形"
End If
Else
s = "不能构成三角形!"
End If
s = a & "," & b & "," & c & "这三条边构成的图形为:" & s
Me.List1.AddItem s
End Sub
Private Sub Command2_Click()
Me.List1.Clear
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询