VB编程 输入三角形三条边长啊,a,b,c的值,根据其数值,判断是否构成三角形.
VB编程 输入三角形三条边长啊,a,b,c的值,根据其数值,判断是否构成三角形.
如果能,判断三角形类型、;等边三角形,等腰三角形,直角三角形,一般三角形.
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漏了一个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 ThenMsgBox "等边三角形" ElseIf a = b Or b = c Or a = c ThenMsgBox "等腰三角形" ElseIf a ^ 2 + b ^ 2 = c ^ 2 Or a ^ 2 + c ^ 2 = b ^ 2 Or c ^ 2 + b ^ 2 = a ^ 2 ThenMsgBox "直角三角形" ElseMsgBox "一般三角形" End IfElse MsgBox "不能构成三角形"End If要定义一下变量类型,我给你完整的,我已经在VB里试过了。Option ExplicitPrivate Sub Command1_Click()Dim a As SingleDim b As SingleDim c As Singlea = 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 ThenMsgBox "等边三角形" ElseIf a = b Or b = c Or a = c ThenMsgBox "等腰三角形" ElseIf a ^ 2 + b ^ 2 = c ^ 2 Or a ^ 2 + c ^ 2 = b ^ 2 Or c ^ 2 + b ^ 2 = a ^ 2 ThenMsgBox "直角三角形" ElseMsgBox "一般三角形" End IfElse MsgBox "不能构成三角形"End IfEnd Sub